tags:

views:

111

answers:

2

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.

+6  A: 

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.

finrod
Actually, I think "succeeds D" means *is **higher** on the chain than D*. The definition says the traits that succeed D are its supertypes with respect to an instance of C.
pelotom
Yes, it seems you are right. Fixing the answer.
finrod
@finrod, no relation to the question, still I'm curious, what's your mother tongue? You refered to class as female "...each class has *her* own..." and I wonder where did it come from. I guess class sounds feminine in your mother tongue.
Elazar Leibovich
@Elazar, it actually *is* feminine in Polish, which is my mother tongue. Funny I'm not consistent throughout the post, though. I must have been thinking in Polish when I was writing the last sentences.
finrod
+1  A: 

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.

Yardena