Hello Linus, This is based on how array types are defined. In general, Vector{subtype} is not a subtype of Vector{supertype}. Try this:
f{R<:Real}(x::Array{R}) = x -Tim On Friday, June 26, 2015 at 8:38:12 AM UTC-7, Linus Härenstam-Nielsen wrote: > > I ran into a problem with types today that I don't know how to interpret. > > If I define a function according to > f(x::Real) = x > it returns x as expected as long as the type of x is a subtype of Real. > However if I define > f(x::Array{Real}) = x > it throws MethodError no matter what I pass as argument. For example when > I try to pass it an Int array: > f([1 2 3; 3 4 5]) > ERROR: MethodError: `f` has no method matching f(::Array{Int64,2}) > > I would expect it to work like > f{T<:Real}(x::Array{T}) = x > and accept any array of reals. Am I missing something? > > > >