# Mixing Union Types and Dictionaries

**URL:** <https://discourse.julialang.org/t/mixing-union-types-and-dictionaries/37462>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 12, 2020, 8:49pm UTC](https://discourse.julialang.org/t/mixing-union-types-and-dictionaries/37462 "2020-04-12T20:49:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Holdmycoffee](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@Holdmycoffee](https://discourse.julialang.org/u/Holdmycoffee)\
**Post date:** [April 12, 2020, 8:49pm UTC](https://discourse.julialang.org/t/mixing-union-types-and-dictionaries/37462/1 "2020-04-12T20:49:50Z")

</div>

Hello,

Newbie here. First, does anyone know why

`Dict{Real, Int64}<:Dict{Union{T, Array{T, 1}}, Int64} where T<:Real`

yields false?

Secondly, I am able define the following two types,

`Dict{Tuple{Union{Array{T,1}, T}, T} where T<:Real, Int64}`

`Union{Dict{Tuple{Array{T, 1}, T} where T<:Real , Int64}, Dict{Tuple{T, T} where T<:Real , θλbuffer}}`

Can someone help me understand the difference?

Thirdly, is there any difference between  
`Dict{Real, Int64}<:Dict{Union{T, Array{T, 1}}, Int64} where T<:Real`  
and  
`Dict{Real, Int64}<:Dict{Union{T, Array{T, 1}} where T<:Real, Int64}` ?

Thanks

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [April 12, 2020, 10:42pm UTC](https://discourse.julialang.org/t/mixing-union-types-and-dictionaries/37462/2 "2020-04-12T22:42:22Z")

</div>

> [@Holdmycoffee](#):
>
> Newbie here. First, does anyone know why
> 
> `Dict{Real, Int64}<:Dict{Union{T, Array{T, 1}}, Int64} where T<:Real`
> 
> yields false?

Because of the type invariance.  
`Dict{Real, Int64}` type does not allow `Array` keys, while all rhs types do.

```julia
Dict{Real, Int64}<:Dict{S, Int64} where S<:Union{T, Array{T, 1}} where T<:Real

```

is `true`, as expected.

> [@Holdmycoffee](#):
>
> Secondly, I am able define the following two types,
> 
> `Dict{Tuple{Union{Array{T,1}, T}, T} where T<:Real, Int64}`
> 
> `Union{Dict{Tuple{Array{T, 1}, T} where T<:Real , Int64}, Dict{Tuple{T, T} where T<:Real, Int64}}`
> 
> Can someone help me understand the difference?

The first is a concrete type - dictionaries whose keys are tuples of values etc. The second is a union of two concrete types - one is dictionaries whose keys are `(array, number)` tuples, another is dictionaries whose keys are `(number₁, number₂)` tuples.

> [@Holdmycoffee](#):
>
> Thirdly, is there any difference between  
> `Dict{Real, Int64}<:Dict{Union{T, Array{T, 1}}, Int64} where T<:Real`  
> and  
> `Dict{Real, Int64}<:Dict{Union{T, Array{T, 1}} where T<:Real, Int64}` ?

In terms of their values, there is no difference, both are `false`. Rhs’s are different, though.  
An instance of `Dict{Union{T, Array{T, 1}} where T<:Real, Int64}` may have mixed `Int`, `Float64` and other `Real` keys, and also arrays thereof. And `Dict{Union{T, Array{T, 1}} where T<:Real, Int64}` is a concrete type.  
`Dict{Union{T, Array{T, 1}}, Int64} where T<:Real` is `UnionAll` type, it is not concrete.
