You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why does Type{T} preserve T as an UnionAll, even though it doesn't preserve the type parameter order? Why are there multiple kinds of type normalization, with differing strength?
#58515
It seems there are two kinds of type normalization in Julia. Neither is documented, even though it seems like it should be, so I'd appreciate some explanations, rationales, terminology corrections, etc.
weak type normalization, which happens in Type{type}: it may reorder the type parameters, but keeps UnionAll as UnionAll
strong type normalization, which happens in, for example, Val{type} (or in Vector{type}): this one is stronger, given that it may even return a DataType when given a UnionAll
julia> functionnormalize_type_strong(::Type{T}) where {T}
function normalize_type_val(::Val{S}) where {S}
S
end
normalize_type_val(Val{T}())
end
normalize_type_strong (generic function with 1 method)
julia> functionnormalize_type_weak(::Type{T}) where {T}
T
end
normalize_type_weak (generic function with 1 method)
julia> normalize_type_weak(Vector{X} where {X>:Any})
Vector{X} where X>:Any (alias for Array{X, 1} where X>:Any)
julia> normalize_type_strong(Vector{X} where {X>:Any})
Vector{Any} (alias for Array{Any, 1})
julia> normalize_type_weak(Tuple{S} where S<:String)
Tuple{S} where S<:String
julia> normalize_type_strong(Tuple{S} where S<:String)
Tuple{String}
julia> normalize_type_weak(Tuple{X, Vararg} where {X})
Tuple{X, Vararg} where X
julia> normalize_type_strong(Tuple{X, Vararg} where {X})
Tuple{Any, Vararg}
julia> normalize_type_weak(AbstractArray{T, N} where {N, T})
AbstractArray
julia> normalize_type_strong(AbstractArray{T, N} where {N, T})
AbstractArray
A previous version of this question on Discourse, got no involvement from someone who might answer authoritatively:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
It seems there are two kinds of type normalization in Julia. Neither is documented, even though it seems like it should be, so I'd appreciate some explanations, rationales, terminology corrections, etc.
weak type normalization, which happens in
Type{type}
: it may reorder the type parameters, but keepsUnionAll
asUnionAll
strong type normalization, which happens in, for example,
Val{type}
(or inVector{type}
): this one is stronger, given that it may even return aDataType
when given aUnionAll
A previous version of this question on Discourse, got no involvement from someone who might answer authoritatively:
Beta Was this translation helpful? Give feedback.
All reactions