My initial question was why this expression returns false:
julia> Vector{Any} === Vector
false
The answer is quite simply that Vector{Any}
is just like any other Vector{T}
,
for which is a subtype of Vector
. Then, we wonder what is Vector
.
Mose Giodano pointed out that:
Vector is a syntactic sugar for Vector{T} where T. It's parametric, but the parameter is very much free.
We can prove it as such:
julia> Vector === (Vector{T} where T)
true
So, we can reason that Vector
is also a parametric type. It's just that the parameter hasn't been
specified yet.
It can get more interesting:
julia> struct Foo{T,S}
x::T
y::S
end
julia> F1 = Foo{Int,S} where S
Foo{Int64,S} where S
julia> F2 = Foo{T,Int} where T
Foo{T,Int64} where T
julia> Foo{Int,Int} <: F1
true
julia> Foo{Int,Int} <: F2
true
julia> F1 <: Foo
true
julia> F2 <: Foo
true
julia> F1 <: F2
false
julia> F2 <: F1
false
Alex Arslan pointed out that Vector
is a UnionAll
type. The documentation is fairly clear about that:
- Vector is an actual example in
UnionAll
doc string - The
UnionAll
in the julia reference manual explains that any paremetric type that does not fully specify all type parameters refers to a collection of parametric types - hence the name of UnionAll.