When playing with the various confusing type relations, I found the following impossible to understand:
There lower bound for T
seems to have no effect? I expect to get Union{}
, but got Int64
. What am I missing here?
Int
is the same as Int64. And the only subtype of Int64 is itself. (The <: is inclusive)
OK, that’s fair, what about the following:
The rule seems inconsistent.
There you have reached one example of this, I think: Vector{Int} <: Vector{Real} is false??? · JuliaNotes.jl
Ref{Number}
is an actual data type: you can create objects of that type that reference data of type Number
:
julia> R = Ref{Number}
Ref{Number}
julia> typeof(R)
DataType
julia> methods(R)
# 2 methods for type constructor:
[1] Ref{T}() where T in Base at refpointer.jl:135
[2] Ref{T}(x) where T in Base at refpointer.jl:136
julia> R(1)
Base.RefValue{Number}(1)
The other is a weird union of data types, which cannot even be instantiated:
julia> S = Ref{T} where Real<:T<:Number
Ref{T} where Real<:T<:Number
julia> typeof(S)
UnionAll
julia> methods(S)
# 0 methods for type constructor:
So they cannot be equal at all.
Thanks. I guess my confusion is that in the first case, the lower bound did not have any effect, in the second one, it did. The T->Ref{T}
“type mapping” is “invariant” but I guess the T->T
type mapping is “covariant” ? Maybe that’s how I should look at it?