I have a few questions on manipulating types:
-
What is the difference between how promote_type and typejoin work?
-
Isn’t it inaccurate to interpret typejoin as a set union, as it is described in the documentation, when the result of
typejoin(Int8,Float64)
is Real? I mean clearly Int64 is not a subtype of Float64 or Int8 but is a subtype of Real, which is a contradiction to the set analogy. -
What is the correct use of a lower bound type in type variables? As I read in the documentation, only leaf (non-abstract) types can be implemented, the rest are all abstract. So is there any benefit to setting an abstract type as a lower bound to a type parameter/variable, when in fact that eliminates all implementable types from the feasible set of types satisfying this condition, hence no argument can possibly match the parametric signature of the function having this type parameter/variable!? Is there another use case I am missing? And if we limit ourselves to a leaf lower bound type, can’t we just use that leaf type straight away as the type of the argument, because all its supertypes cannot be implemented anyway? Similarly, using multiple leaf types in a Union as a lower bound type, e.g.
Union{Int,Float64}
is not very useful; because we can just use theUnion{Int, Float64}
directly as the type of the argument. -
Just to confirm my understanding, does the bound field printed when running xdump on a type’s parameters, e.g. xdump(Array.parameters), mean whether the type variable refers to a specific type to be determined based on the argument, or if it is just an arbitrary/abstract/anonymous type parameter, and all arbitrary type parameters are assumed equal? Consider the following example:
S = TypeVar(:S, false); T = TypeVar(:T, false); Array{S} == Array{T}
returns true, because S and T are both arbitrary and hence they are treated to be equal when comparing types (including type comparison to find a suitable method for the arguments). However,S == T
returns false, which means that they are only treated as equal when used as type parameters. Someone please confirm my understanding if my explanation was clear enough.