Promoting union types

NOT RECOMMENDED BECAUSE THIS USES INTERNALS but here it is anyway:

julia> Base.promote_union(Union{Float64, Union{Complex{Rational{Int}}, Rational{Int}}})
ComplexF64 (alias for Complex{Float64})

Note that I had to wrap everything in an additional Union to make this work. I’ll recommend you take a peek at the implementation. All it does is recurse on any unions and promote_type when it reaches a pair of non-unions, so you could roll your own version if you wanted to.

3 Likes