In the Scala 2.8 reference, section 5.3.3 page 69 (77 in the pdf) the following paragraph appear:
Assume a trait
D
defines some aspect of an instancex
of typeC
(i.e.D
is a base class ofC
). Then the actual supertype ofD
inx
is the compound type consisting of all the base classes inL(C)
that succeedD
.
What does the notation L(C)
means (in the origi开发者_开发问答nal text it's a calligraphic capital \ell
like symbol)?
What does the phrase "classes... that succeed D
" means? I'm not familiar with the notation.
The bottom line is, L(C)
consists of all the base classes (the whole inheritance hierarchy of C, including traits) ordered as a chain, with Any
at the top, and C
at the bottom. Succeeds D
means, is higher in the chain then D
.
The longer explanation is that we want to know, for each class, its "parent" -- for implementation purposes and general clarity (it's terribly messy in C++, where unbounded multiple inheritance is allowed). In Java it is simple -- you only have a single direct superclass. However, because of the mixin-class composition in Scala, which is a form of multiple inheritance (from one superclass + possibly several traits), the base classes of any class form a directed acyclic graph. L(C) is the linearization of the C's base classes -- starting from the superclass, and adding the traits (and their base classes) such that they form a chain and each class has her own base classes above itself. You can read more about it in Section 6 of the overview of Scala. It's a nice, comprehensive outline of the feature.
L(C) is class linearization. Then "succeeds" regards to the position in the result sequence. Linearization is defined in chapter 5.1.2 of the spec.
精彩评论