I have an abstract type “Foo” that has a number of children: “Bar”, “Car”, “Dar”.
I also have a function “f” that takes an array of “Foo” objects as arguments.
function f(a::Array{Foo, 1})
But when I try to run the function with:
julia> typeof(b)
Bar
julia> f([b])
I get an error like:
ERROR: MethodError: no method matching f(::Array{Bar,1})
Closest candidates are:
f(::Array{Foo,1})
Is there any way to force the function to accept the children of “Foo”? I can’t write methods for every possible array of “Bar” “Dar” and “Car”, so I’m stuck until I can find another solution.
Array{Foo, 1} is a specific concrete type where each entry in it can be any subtype of Foo independently from one another. Array{<:Foo, 1} on the other hand is the set of all 1D Arrays which contain elements which are subtypes of Foo.