Sudete already answered your question, but I still find it interesting to trace what happens here:
Incidentally:
julia> [[1,2],[3,[4,5]]]
2-element Array{Array{Any,1},1}:
[1, 2]
[3, [4, 5]]
but:
julia> [[1,2],[[3,],[4,5]]]
2-element Array{Array{T,1} where T,1}:
[1, 2]
[[3], [4, 5]]
It boils down to the following:
Julia uses promote_rule to find a common type for the array elements:
julia> typeof([1,2])
Array{Int64,1}
julia> typeof([3,[4,5]])
Array{Any,1}
julia> promote_rule(Array{Int64,1}, Array{Any,1})
Array{Any,1}
which ultimately calls this to decide which type to promote to:
julia> Base.el_same(Any, Array{Int64,1}, Array{Any,1})
Array{Any,1}
from here: https://github.com/JuliaLang/julia/blob/c31d126ac7ee425f3e121c16016844fb64a0c950/base/range.jl#L949
which basically says:
If one of the containers doesn’t need to change in type, take that one. If that doesn’t work, make a typejoin. (a typejoin would give you your expected result here, an Array{T,1} where T
)
Ultimately, someone decided that it is better to have a concrete type if possible and only fallback to Union types if that doesn’t work.
That makes me think it’s intended behaviour, maybe necessary for good performance. I can’t give you more information on whether that is fully intended. Rules come from this commit:
https://github.com/JuliaLang/julia/pull/22757
So (and I hope thats not inappropriate) we might need to ask @jeff.bezanson about this.