Here is my understanding of Type.  Beware though, it might be completely 
wrong!!!

`Type` in itself is just an ordinary abstract type:

julia> typeof(Type)
DataType

julia> super(Type)
Any

and DataType is a subtype of it

julia> subtypes(Type)
3-element Array{Any,1}:
 DataType       
 TypeConstructor
 UnionType      

julia> DataType.abstract
false

I think this should answer your 1st question.

Where `Type` is special is with respect to `isa` and thus method
dispatch where this works:

julia> bar{T}(::Type{T}) = T
bar (generic function with 1 method)

julia> bar(Int)
Int64

julia> isa(Int, Type{Int})
true

I think there is some special handling of Type to make that possible.
As of course, I can't replicate this myself:

julia> abstract MyType{T}

julia> foo{T}(::MyType{T}) = T
foo (generic function with 1 method)

julia> foo(Int)
ERROR: MethodError: `foo` has no method matching foo(::Type{Int64})

julia> isa(Int, MyType{Int})
false

I think the `isa(Int, Type{Int}) == true` is hard-coded somewhere in the
internals of Julia.  For normal instances this holds:

julia> isa(5,Int)
true

implies

julia> typeof(5)<:Int
true

But for Types this is not true:

julia> isa(Int,Type{Int})
true

julia> typeof(Int)<:Type{Int}
false

> I understand that DataType <: Type, since all types are subclasses of
> Type.

No, for instance `(Int<:Type)==false`, but all types are subtypes of Any.  

> Intuitively, I also understand that isa(Float64, DataType). But
>
> 1. how can Type be both a super- and a subclass of DataType, when
>
> super(Type{Float64})
>
> and
>
> Any <: DataType is false, and
>
> 2. how does this square with invariance? or that doesn't apply to types?

Note sure I understand this.

> Sorry, I am just having a hard time visualizing the graph of types.

So, it's simple Any:>Type:>DataType:>None.

Reply via email to