Why Union{Missing, Int}==Union{Int, Missing}, while Tuple differs?

I know it is necessary for Union to behavior like this, while the type parameter order of Tuple must batter.

But how? Is Union specially handled by the julia compiler?

The definition of two types T and S being equal is that T<:S && S<:T. There are also some normalization for types, e.g.:

julia> a = Union{Missing, Int}
Union{Missing, Int64}

julia> b = Union{Int, Missing}
Union{Missing, Int64}

so they actually end up being represented identically.


Yeah, think of a Union as a set of Types, i.e. unordered collection of unique items, whereas a Tuple Type is just an ordered list of Types. You can see the set behavior of Union by doing things like Union{Int, Int, Float64}, or as you’ve noticed, Union{Int, Missing} == Union{Missing, Int}.