I am trying to write two functions with the same name that can use Julia's multiple dispatch system and include arrays and arrays of arrays.
Suppose these three input variables
a=Array[[1,2,3],[4,5,6]]
b=[1,2,3]
c=[rand(10) for i in 1:2]
And I write two functions like
function test(x::Array{Array})
println("received an array of array => $(typeof(x))")
end
function test{T<:Number}(x::Array{T,1})
println("received a vector. converting.....")
nx = Array[x]
test(nx)
end
This approach works for aand b, but not c.
test(a)
test(b)
test(c)
Now, if I change the definition of a function to x::Array{Array{Float64,1},1}, this will work. But my question is not what Array{Array}should any array arrays accept?
How to work with an internal type parameter in an array of arrays?
source
share