I have a quick question on the type system of Julia.
My mental model of a type is simply a set of values. We can say a value v is an instance of a type T if v is in the set T. We can also say a type T is a super-type of a type S if T contains the set S.
But Julia also enforces that every value v is an instance of a concrete type C.
Now, my question is this:
If v is an instance of T, must T be a super-type of C?
In other words, if C is a concrete type and (T intersection C) is non-empty, must T be a super-type of T (edit: I mean āmust T be a super-type of Cā)? This is clearly false for C an abstract type: A counterexample is C = Union{TypeA, TypeB} and T = TypeA.
If this is not true, then is it at least true that two different concrete types must have empty intersection? This seems to me like it should be true: If not, there would be ambiguity as to what type the typeof function should return when passed values in this intersection.
A third question: Is there a complete, rigorous description of the type system somewhere? Iām looking for something thatās as axiomatic as possible. For example, two axioms of the type system appear to be: 1. Every value is an instance of a concrete type, 2. Concrete types cannot sub-type one another. But these axioms leave open the possibility that two concrete types have non-empty intersection - this is what Iām trying to clarify in my second question, above.
Effectively, are you asking if a \in T, a \in C implies C \subseteq T? It doesnāt.
No, in Julia types are not their own supertypes.
Yes, this is correct.
Not that I am aware of (but the code may of course qualify as a rigorous description, just not in the language of math).
Generally an axiomatic approach is not needed, it would be a lot of notation for little insight as the type system is pretty intuitive conceptually. But if you insist on creating one, keep parametric types in mind, they complicate the picture a bit as technically Julia does not consider the UnionAll a supertype, eg
julia> Rational{Int} <: Rational
true
julia> supertype(Rational{Int})
Real
If C is a concrete type, and T is another type (concrete/abstract/whatever), and the intersection of T and C is non-empty, must we necessarily have that T is a super-type of C?
Of course, it is easy to come up with sets T and C such that this is not true. But types cannot be arbitrary sets of values.
The reason I was wondering whether or not this is true is that it would be nice to say that a valueās concrete type is the node on the type graph such that every type for which that value is an instance is a super-type of this node (i.e. āa parent ofā this node).