How to make a function accept children of an abstract type?

Try

function f(a::Array{<:Foo, 1})

or

function f(a::Array{T, 1}) where T <: Foo

instead.

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.

3 Likes