I'm gonna explain my problem on a minimal example. Let's say I have three files:
A.jl
module A
export Atype, f
type Atype
end
f = function(x::Atype)
println("f called with A")
end
end #module
B.jl
module B
export Btype, f
type Btype
end
f = function(x::Btype)
println("f called with B")
end
end #module
Main.jl
using A
using B
main = function()
x = Atype()
f(x)
end
main()
Here I have two versions of f
function. If I understand the idea of the multiple dispatch correctly, it should be deducted during runtime which version should be used. Hence, I expected that running Main.jl would print f called with A
. Unfortunately, I get
$ julia Main.jl
ERROR: type: anonymous: in typeassert, expected Btype, got Atype
in include at /usr/bin/../lib64/julia/sys.so
in process_options at /usr/bin/../lib64/julia/sys.so
in _start at /usr/bin/../lib64/julia/sys.so
while loading /home/grzes/julia_sucks/Main.jl, in expression starting on line 9
If I comment out using B
, it works fine. Clearly, f
from B.jl overwrote f
from A.jl.
So, the question is: where does the problem lie? In my approach or in the version of Julia I use (0.3.7)? How can I circumvent this?
Note that replacing using A
with import A
and using fully qualified names (e.g. A.f
) is not a good solution. It contradicts with the crux of multiple dispatch -- at compile time I don't know if I should use A.f
or B.f
.