Equality of unwrapped unionalls

It’s easier to flip the question, when do you need the same TypeVar instance? When the same type parameter is shared by several places, like T in the line struct MyArr{T,N} and the line arr:Array{T,N} of the definition:

julia> Base.unwrap_unionall(MyArr).parameters[1] === unwrap_arr_field.parameters[1]
true

TypeVar identity is how Julia ensures both places get the same T value you specify per concrete type. Flipping back to your question, we thus need different instances for different type parameters that happen to share a name and bounds but can be specified with different values. That might have been doable with an immutable type if there was an additional field for identity, but everything has an address, might as well use it.

Source: More about types · The Julia Language

1 Like