@David: Thank you for this. It does appear to resolve a class of problems.
On Tuesday, May 5, 2015 at 11:43:34 AM UTC-4, David Gold wrote:
>
> @Scott: Glad to hear it may be useful to you! If you encounter any bugs,
> or if you think of a related feature you'd like to see, please do open an
> issue in the github repo. I'll try my best to accommodate.
>
> @Sisyphuss: As Stefan notes, this is an additional feature. I intend it to
> complement the fix in issue #4345, which actually provides the cleanest
> environment for using merge!().
>
>
> As soon as I figure out git I will be able to turn this into a real
> package. I intend for that to happen asap.
>
> D
>
> On Tuesday, May 5, 2015 at 8:31:17 AM UTC-4, Scott Jones wrote:
>>
>> Great! +1 This will solve a lot of my problems about trying to maintain
>> good software engineering practices with Julia, (but not all, it doesn't
>> address being able to keep the implementation separate from the
>> abstraction...
>> I really don't want others to have the ability to play with my private
>> parts [as somebody else here so aptly put it])
>>
>> Scott
>>
>> On Monday, May 4, 2015 at 3:08:43 PM UTC-4, David Gold wrote:
>>>
>>> Based on recent discussions, it seems that at least some people would
>>> like the option to have unqualified use of a function name dispatch
>>> "across" modules when the argument on which the function is called
>>> unambiguously specifies an exported method. While Julia doesn't do this
>>> automatically, one option is for the user explicitly to "merge" functions
>>> defined in different modules. I've been working on an implementation of
>>> this functionality that doesn't require users to copy a bunch of method
>>> definitions:
>>>
>>> julia> using MetaMerge
>>>
>>> julia> f() = nothing
>>> f (generic function with 1 method)
>>>
>>> julia> module A
>>>
>>> export f
>>> immutable Foo end
>>> f(::Foo) = print("This is Foo.")
>>> f(x::Int64) = x
>>>
>>> end
>>>
>>> julia> module B
>>>
>>> export f
>>> immutable Bar end
>>> f(::Bar) = print("This is Bar.")
>>> f(x::Int64) = 2x
>>>
>>> end
>>>
>>> julia> using A, B
>>> Warning: using A.f in module Main conflicts with an existing identifier.
>>> Warning: using B.f in module Main conflicts with an existing identifier.
>>>
>>> julia> methods(f)
>>> # 1 method for generic function "f":
>>> f() at none:1
>>>
>>> julia> merge!(f, (A,f), (B,f))
>>>
>>> julia> methods(f)
>>> # 3 methods for generic function "f":
>>> f() at none:1
>>> f(x1::Foo)
>>> f(x1::Bar)
>>>
>>> julia> f(A.Foo())
>>> This is Foo.
>>> julia> f(B.Bar())
>>> This is Bar.
>>>
>>>
>>> One can also use merge!() while writing modules to allow for unqualified
>>> use of a name within the module, such as in the definition of h below:
>>>
>>> julia> module C
>>>
>>> export f
>>> using MetaMerge, A, B
>>> f(::Union()) = nothing
>>> merge!(f, (A,f), (B,f), conflicts_favor=A)
>>> h(x::Int64) = f(x)
>>>
>>> end
>>>
>>> julia> using C
>>> Warning: using C.f in module Main conflicts with an existing identifier.
>>>
>>> julia> C.h(2)
>>> 2
>>>
>>>
>>> The repo is here: https://github.com/davidagold/MetaMerge.jl (I've
>>> never versioned anything before, so I apologize in advance if the numbers
>>> seem silly/arbitrary). I hope it can be useful to some. Folks should feel
>>> free to leave suggestions, bug reports or requests for other kinds of
>>> functionality that they'd like to see from something like this. I'll do my
>>> best to accommodate, though I'm rather new to programming and hence cannot
>>> make any promises.
>>>
>>> Cheers,
>>> David
>>>
>>