Constant type semantics

Consider we have some abstract type

abstract type Point{T, N} end

What is the main difference between

Point3{T} = Point{T, 3}


const Point3{T} = Point{T, 3}

What is the const modificator meaning related to the type declaration? I did not find exact explanation in the documentation.

I think in this instance they are equivalent. consider

julia> Point3{T} = Point{T, 3}
Point{T,3} where T

julia> Point3 = 11
ERROR: invalid redefinition of constant Point3
 [1] top-level scope at REPL[25]:1

thus Point3 is implicitly made a const. However, if you don’t have type parameters, then you should use the const:

julia> Point3I = Point{Int, 3}

julia> Point3I = 11

as then the variable is not automatically marked as const, and thus if you use it inside functions it will lead to type-unstable code.

To make the notation consistent, I would then also use const in the first example, even though it is not needed.


Thank you for the explanation!