Let's say, we have 2 modules:

module A
export foo
foo(n::Int) = println("A")
end


module B
export foo
foo(s::String) = println("B")
end

and then in REPL:

julia> using A
julia> using B
!julia> methods(foo)
 # 1 method for generic function "foo":                                     
                                                                            
              
foo(s::String) at /home/<user>/.julia/v0.3/B/src/B.jl:4

so method `A.foo` is shadowed. But at the same time purely in REPL or 
single module: 

 julia> bar(x::Int) = println("#1")
 bar (generic function with 1 method)


 julia> bar(s::String) = println("#2")
 bar (generic function with 2 methods)


!julia> methods(bar)
 # 2 methods for generic function "bar":                                   
                                                                            
                 
 bar(x::Int64) at none:1
 bar(s::String) at none:1

Methods are added to a function. 

My question is what is the idea behind this behavior and what to do if `A` 
and `B` are 2 independent modules, having same method `foo` by coincidence 
(expect for using qualified names, of course)? 




Reply via email to