# Array of unions of subtypes

What is the difference between Array{Union{Nothing, <:Real}} and Array{<:Union{Nothing, Real}}?
I expect Vector{Int64} to be a subtype of the array of the union of nothing and subtypes of real, but only the latter gives true. What is the meaning of <:Union{Nothing, Real}?

Array{<:Union{Nothing, Real}} is a syntax sugar for Array{T} where {T<:Union{Nothing, Real}}.

Itâ€™s called UnionAll which means Union{Array{Nothing}, Array{Real}}. See the talk linked below for more details.

Union{Array{Nothing}, Array{Real}} doesnâ€™t seem to include Vector{Union{Nothing, Int64}} â€¦ or does it?
So now my understanding is that Union{Nothing, Real} isnâ€™t simply a union of type Nothing and abstract type Real, but also includes all concrete subtypes in the set. I suppose Union{Nothing, <:Real} doesnâ€™t mean the way I expect it to be, as in the union of type Nothing and all of the concrete subtypes of Real.

julia> x = Array{T} where T<:Union{Nothing,S} where S <: Real
Array{T} where {S<:Real, T<:Union{Nothing, S}}

julia> y = Array{Union{Nothing, <:Real}}
Array{Union{Nothing, Real}}

julia> x == y
false

julia> y <: x
true

julia> x <: y
false
1 Like