I am surprised and went through the source to find what happens. The stuff happens in typejoin,
which is very complicated and does not seem to use promotion of eltype. Can someone explain that to me, and why the simpler case is handled but not the more complicated one?
Actually my question is motivated by a problem I have in my code, with different types. I am expecting that when I have defined (or Julia has defined) T=promote_type(T1,T2) (and a promote_rule also) then elements in a mixed vector of T1 and T2 are promoted to T (this happens) and also that mixed Vector{T1} and Vector{T2} in a Vector are promoted to Vector{T} (this is very inconsistent, depending on T1 and T2).
julia> promote_type(BigInt, Float32)
BigFloat
julia> promote_rule(Vector{BigInt}, Vector{Float32})
Vector{T} where T (alias for Array{T, 1} where T)
Basically I think 1) it’s not clear there’s a definitive rule regarding how far should Julia go to promote different nested types such that it appears to be natural and “completed” to our eyes. 2) even if there is a mathematically sound rule, it may be too much cost to *always do it.
I believe this is an implementation detail (depending on heuristics). (think of trying to document when will a function be inlined)
Overall, there is never a type-promotion covariance(?) promised by Julia in the docs anywhere to begin with, so there’s no need to document a non-feature.
Well, we saw some examples where the promotion happened. I would think there is no problem
when a and b are arrays; or otherwise one should prohibit the examples which worked above.
For me the problem is the inconsistency.
Inconsistency is indeed a problem.
I’d just ignore the existence of type promotion for arrays of arrays and write my own function for the specific case I need, though.
One could argue that the problem you highlight is a question of !== being too coarse a measure of equality for the case in hand.
According to the manual:
39.18 Be careful with type equality
You generally want to use isa and <: for testing types, not ==. Checking types for exact equality typically only makes sense when comparing to a known concrete type (e.g. T == Float64), or if you really, really know what you’re doing.