开发者

"class A succeeds class B" means in Scala reference?

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 instance x of type C (i.e. D is a base class of C). Then the actual supertype of D in x is the compound type consisting of all the base classes in L(C) that succeed D.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜