Description
In an email discussion we came to the conclusion that it made sense to have multiple inheritance in Julia with one fairly simple restriction:
If two abstract types are are used for dispatch in the same "slot" of the same generic function object then they cannot share a common, concrete descendant (all types share
None
as a common abstract descendant).
This restriction, together with Julia not allowing inheritance from non-abstract types, seems to address all the practical issues one typically encounters with multiple inheritance. The following, for example, would be disallowed:
abstract A
abstract B
type C <: A, B
end
f(A) = 1
f(B) = 2 # ERROR: A and B share a common descendant
Note that a generic function is an object external to all types, not a name inside of a type as it would be in a traditional object-orientation language. Thus, one can have f(a::A)
in one namespace and f(b::B)
in another namespace without problems, so long as the f
s in these two namespaces are distinct generic function objects.