Hello,

I am trying to define the type of the input vector to be either Int or
Float. In order to do that I defined a union:

IntOrFloat = Union{Int, AbstractFloat}

Next I write to functions definitions which I expected to be equivalent:

#-------------------------------------#
function f1(v::Array{IntOrFloat,1})
     mean(v)
end
println( f1([1.0, 2.0]) )
println( f1([1, 2]) )

function f2(v::Vector{IntOrFloat})
     mean(v)
end
println( f2([1.0, 2.0]) )
println( f2([1, 2]) )
#-------------------------------------#

But when I run it I see an error:

ERROR: LoadError: MethodError: `f2` has no method matching
f2(::Array{Float64,1})

Why is that?
Vector{} and Array{...,1} are equivalent:

julia> Array{IntOrFloat,1}==Vector{IntOrFloat}
true

-- 
Alexandr

Reply via email to