Mixing Union Types and Dictionaries

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

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

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

is true, as expected.

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.

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.

1 Like