Type compare

Other way around. This is the one example of an abstract type subtyping (and being more specific than) a concrete type I can think of.

julia> Type{Int} <: typeof(Int) # DataType
true
julia> Tuple{Type{Int}} <: Tuple{DataType}
true

As you quoted, it’s weird and doesn’t fit the wider subtyping rules, but this “hack” allows dispatch on specific types (as long as they’re not packaged in tuples). It would be more consistent with the rules if types were more like functions i.e. typeof(T) is a concrete parametric or singleton type that subtypes an abstract Type, but Julia v0 / v1 didn’t turn out that way.

The confusing part for me is I had always assumed that dispatch was done on a tuple of the function and the arguments, e.g. f(Int, 1.0) dispatches on Tuple{typeof(f), DataType, Float64}. And that’s perfectly capable of being dispatched to a method function f(T::Type{Int}, x::AbstractFloat). So there should be some explanation of how the dispatch to Type{Int} is really handled and why it doesn’t work when there’s an extra level of nested Tuple e.g. f( (Int, 1.0) ) dispatching on Tuple{typeof(f),Tuple{DataType,Float64}}.

1 Like