Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

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 original 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.

like image 868
Elazar Leibovich Avatar asked Jul 19 '10 10:07

Elazar Leibovich


2 Answers

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.

like image 143
finrod Avatar answered Sep 28 '22 01:09

finrod


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.

like image 41
Yardena Avatar answered Sep 28 '22 00:09

Yardena