It seems that all concrete types in Julia are leaf types, but the reverse is not true. For example, Type{Int64}
is a leaf type but it is not concrete:
julia> Type{Int64}.abstract
true
julia> Type{Int64}.isleaftype
true
My understanding is that this makes sense, because there are no values that have type Type{Int64}
. The type Int64
has concrete type DataType
. However, because Type{Int64}
has no nontrivial subtypes, it is considered a leaf type.
However, the documentation of isleaftype
is a little confusing:
isleaftype(T)
Determine whether T is a concrete type that can have instances, meaning its
only subtypes are itself and Union{} (but T itself is not Union{}).
Type{Int64}
cannot have instances, so the first sentence suggests that it is not a leaf type. However, it is indeed true that its only subtypes are itself and Union{}
, so the second sentence suggests that it is.
Is the documentation conflating leaf types and concrete types, and if so, which meaning is correct?
Type Unions A type union is a special abstract type which includes as objects all instances of any of its argument types, constructed using the special Union keyword: julia> IntOrString = Union{Int,AbstractString} Union{Int64, AbstractString} julia> 1 :: IntOrString 1 julia> "Hello!" :: IntOrString "Hello!"
You're right; the part about having instances was probably added to give a more intuitive sense of which types these are, but is not strictly correct (if having instances is defined as typeof(x) === T
).
The .abstract
field is a property of the type family (Type
) that basically tells you whether the type was declared with abstract
(as opposed to type
or immutable
or bitstype
). This just tells you whether some members of the family can have declared subtypes, and so is not directly related to being a leaf type or concrete type. As you observe, Type{Int}.abstract
is true, but an example that goes the other way is that Complex.abstract
is false, even though Complex
by itself is neither leaf nor concrete since since the parameter is unspecified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With