# Array of unions of subtypes

**URL:** <https://discourse.julialang.org/t/array-of-unions-of-subtypes/66105>\
**Category:** New to Julia\
**Created:** [August 10, 2021, 4:05am UTC](https://discourse.julialang.org/t/array-of-unions-of-subtypes/66105 "2021-08-10T04:05:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hideakiv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hideakiv/32/22193_2.png) [@hideakiv](https://discourse.julialang.org/u/hideakiv)\
**Post date:** [August 10, 2021, 4:05am UTC](https://discourse.julialang.org/t/array-of-unions-of-subtypes/66105/1 "2021-08-10T04:05:40Z")

</div>

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}`?

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [August 10, 2021, 4:38am UTC](https://discourse.julialang.org/t/array-of-unions-of-subtypes/66105/2 "2021-08-10T04:38:27Z")

</div>

` 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.

[![](https://global.discourse-cdn.com/julialang/original/3X/9/1/91e03278926423ca9169e8215cee56a72a343cea.jpeg "JuliaCon 2018 | Subtyping made friendly | Francesco Zappa Nardelli") ](https://www.youtube.com/watch?v=Y95fAipREHQ&t=1245)

---

<div class="post-metadata">

**Author:** ![hideakiv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hideakiv/32/22193_2.png) [@hideakiv](https://discourse.julialang.org/u/hideakiv)\
**Post date:** [August 10, 2021, 4:50am UTC](https://discourse.julialang.org/t/array-of-unions-of-subtypes/66105/3 "2021-08-10T04:50:53Z")

</div>

`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`.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [August 10, 2021, 5:05am UTC](https://discourse.julialang.org/t/array-of-unions-of-subtypes/66105/4 "2021-08-10T05:05:45Z")

</div>

> [@hideakiv](#):
>
> 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.

```julia
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

```
