What's with the invariant parametric types gotcha?

No, the syntax really isn’t the core of the issue here. A Vector{Integer} is a real type, and one you might even use at some point, it’s just that [1, 2, 3] doesn’t give you one.

A Vector{Integer} is a vector in which every element can be a (potentially different) subtype of Integer:

julia> x = Vector{Integer}()
Integer[]

julia> push!(x, 1)
1-element Array{Integer,1}:
 1

julia> push!(x, big(2)^big(100))
2-element Array{Integer,1}:
                               1
 1267650600228229401496703205376

This is different from Vector{Int64} in which every element is exactly the concrete type Int64. It’s also different from Vector{<:Integer} which is a set of types describing any Vector whose element type is any subtype of Integer. Vector{Int64} and Vector{Integer} are both members of that set:

julia> Vector{Int64} <: Vector{<:Integer}
true

julia> Vector{Integer} <: Vector{<:Integer}
true

but they have no relationship to one another otherwise:

julia> Vector{Int64} <: Vector{Integer}
false
8 Likes