Hi,
I have a module with a function that I'd like to be overloaded, one version
should take as an argument a type that I declare somewhere else and later
(i.e. this module is required before the argument type) and another version
should be an Array of such a type. That's the idea.
Simple example: I have three files.
In my_module.jl:
function f(s)
println(s.x)
end
function f(sl::Array{Any})
for s in sl
f(s)
end
end
In my_type.jl:
type state
x
y
z
end
In my_main.jl:
include("my_module.jl")
include("my_type.jl")
s1 = state(1.0, 5.0, 7.0)
s2 = state(2.0, 6.0, 8.0)
sl = [s1, s2]
println("f(s1)")
f(s1)
println("f(s2)")
f(s2)
println("f(sl)")
f(sl)
If I run: julia my_main.jl
I get this error: "ERROR: type Array has no field x" because it uses the
first version of the function, nothing prevents it indeed.
I would like to find a way to make it understand it has to choose the
second version of the function. How could I do that?
Thanks a lot,