Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Strange re-typing of arrays of numbers

$
0
0

Hello, I was putting together some multiple-dispatches to find that it doesn’t work as I would expect. Or rather, maybe dispatching works perfectly great, but my arrays of numbers get re-typed strangely.
When you have a list of lists of which all but one are integer lists:

x = [[2,3,4], [2,5], []]

it correctly assumes the type:
Array{Array{Any,1},1}

But if you afterwards try to extract the type of the first sub-list like so:

typeof(x[1])

It is surprisingly (for me) not a list of integers (but it is), but it is Array{Any,1}.

Could someone explain to me what is happening in the background? I wanted to use a parametric multiple dispatch that would handle list of sublists of the same type differently than a list of sublists of different types. So why doesn’t the type above get re-typed to list of integers? My multi-dispatch with which I discovered this behavior:

function(a::Vector{T}, b::Vector{T}) where {T}
    ..
end

function(a::Vector{T}, b::Vector{U}) where {T, U}
    ..
end

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles