DataType and Type{DataType}

I have a confusing question so I will try to be as precise as possible in my wording.

As far as I understand every value in Julia is of a single concrete type. Types themselves are also values.

For example DataType is a type under whose value umbrella fall values like Int64, AbstractString, and DataType (also a value ) itself.

The value isa type construct tells you whether a value is of a specific type. It returns true if the type is the concrete type of the value, or if type is an abstract super type of the concrete type of the value.

Everything above was my well defined simple understanding until I thought too hard and confused myself.

The confusion arises because Type{DataType} is an abstract type. The concrete type of DataType is DataType. DataType isa Type{DataType} is true. However DataType <: Type{DataType} is false. Meaning something about the rules I listed above is wrong.

It makes sense to me that DataType <: Type{DataType} has to be false otherwise Int64 isa Type{DataType} would also return true which we don’t want. But how then is this Type{T} parametric abstract type defined to achieve such magic? Is this some hardcoded type that is just different inside the compiler. Or could I define my own MyType{T} with the same behavior as Type{T} in the language itself.

No, Type is magic and has special hardcoded subtyping rules.

2 Likes