I have a function
function square(a::Real)
return a[1]^2
end
this works with both Int64
and Float64
. But if I make it accept an array of Real
s I get this
julia> function square(a::Array{Real})
return a[1]^2
end
square (generic function with 1 method)
julia> square([Float64(2)])
ERROR: MethodError: no method matching square(::Vector{Float64})
Closest candidates are:
square(::Array{Real}) at REPL[1]:1
Stacktrace:
[1] top-level scope
@ REPL[2]:1
julia> square([Int64(2)])
ERROR: MethodError: no method matching square(::Vector{Int64})
Closest candidates are:
square(::Array{Real}) at REPL[1]:1
Stacktrace:
[1] top-level scope
@ REPL[3]:1
How can I correctly type a function that can accept an array of Real
numbers?