Error caused by Sending Vector{Int64} to Vector{Integer} type function

I know that if I had some function

function a(b::Integer)

then I can call a using parameters of any sub-type of Integer, so Int64 or Int32, for example.

I am wondering if there is any way to do the same thing with vectors, by this I mean make some function
function u(v::Vector{Integer})
which accepts parameters which are vectors whose elements are subtype of the Integer type.

Please let me know if there is any way to do this in Julia.

Thank you,

Jack

The signature should be u(v::Vector{<:Integer}). Parametric types in Julia are invariant rather than covariant (or contravariant).

6 Likes

This is a FAQ: Why doesn’t it work to declare foo(bar::Vector{Real}) = 42 and then call foo([1])?

3 Likes