Typing declaring Real numbers and using Vectors as default arguments

Vector{S} is not a subtype of Vector{T} even if S <: T. This is documented in the manual: Types · The Julia Language, and you can also find many discussions about it here: Search results for 'invariant type' - JuliaLang The correct function signature for you is:

mul(a, m::Vector{<:Real}=[1,2])
# or
mul(a, m::Vector{T}=[1,2]) where {T<:Real}

The former is just syntactic sugar for the latter.

As for your second question, I’m not sure I understand. Safe in what way? I wouldn’t hesitate to use it, anyway. Why is the python version with None as default preferred?

BTW, since your function anyway returns a tuple, maybe you should allow tuple input?

1 Like