# Composite type comparison

Something similar to this probably has been asked and answered before, but my search-Fu is not strong enough to find the answer.

I can’t figure out why the last comparison doesn’t succeed.

``````julia> x
([1], [1])

julia> typeof(x)
Tuple{Vector{Int64}, Vector{Int64}}

julia> typeof(x) <: Tuple
true

julia> typeof(x) <: Tuple{Vector, Vector}
true

julia> a
3-element Vector{Tuple{Vector{Int64}, Vector{Int64}}}:
([1], [1])
([1], [1])
([1], [1])

julia> typeof(a)
Vector{Tuple{Vector{Int64}, Vector{Int64}}} (alias for Array{Tuple{Array{Int64, 1}, Array{Int64, 1}}, 1})

julia> typeof(a) <: Vector
true

julia> typeof(a) <: Vector{Tuple}
false
``````

I verified the “almost” full type, using Int but not Int64, does work.

``````julia> typeof(a) == Vector{Tuple{Vector{Int},Vector{Int}}}
true
``````

Strangely, this doesn’t work…

``````julia> typeof(a) == Vector{Tuple{Vector{Number},Vector{Number}}}
false
``````

even though

``````julia> Int64 <: Number
true
``````

Does this help?

In addition, the Tuple type is the only type which is covariant, which means that a Tuple is subtype of another Tuple if each of its element types is a subtype of the corresponding element type in the supertype Tuple.

2 Likes