1

Topic: and linearization

I read some books on Scala and there new entities -  (traits) and "new type of inheritance" - linearization are entered. But something not so I understand all it. And who  can explain on fingers, in particular as it is arranged on a low level, well and generally. With normal inheritance all is quite clear, and in general it is possible to tell that it is low-level enough mechanism (if there there is no virtuality) - the base class simply turnes on in derivative as its part. And how are arranged ?

2

Re: and linearization

Well, not such they and new. Under slightly other type all it together with  has been implemented in ommon lisp in 80th years of last century. And as it is arranged - most it was interesting to learn. It seems, in scala recently there were big changes in it. At least, very much I hope that under  it will be sometime possible to write on scala without dancings with retroguard. Perhaps, it became already possible with an output 2.12

3

Re: and linearization

Hello, x-code, you wrote: XC> I Read some books on Scala and there new entities -  (traits) and "new type of inheritance" - linearization are entered. But something not so I understand all it. Same  under other name.

4

Re: and linearization

Hello, x-code, you wrote: XC> I Read some books on Scala and there new entities -  (traits) and "new type of inheritance" - linearization are entered. XC> but something not so I understand all it. XC> and who  can explain on fingers, in particular as it is arranged on a low level, well and generally. XC> With normal inheritance all is quite clear, and in general it is possible to tell that it is low-level enough mechanism (if there there is no virtuality) - the base class simply turnes on in derivative as its part. Consider that it is interfaces (in sense of Java or Sharpa) having implementations of methods. Well, and linearization is a mechanism of elimination of ambiguities. Generally some successors can have implementations for some method. What of them will be used defined by order in the inheritance list. XC> and how are arranged ? They are arranged in any way. It is magic of compile time. At compilation from several  and one base class one class gathers. The code is somehow stored I do not know. We in Nitra the Author: VladD2 Date: 12.01.17 multiple inheritance for the abstract types AST and characters. It is very similar on , but differs that ambiguities (conflicts) we suggest to resolve by property redefinition (at us language admits only them) in a class investigating two or more implementation.

5

Re: and linearization

Hello, anonymous, you wrote: A> Same  under other name. In Wikipedia any turbid difference between  and  and whether generally not clearly is a difference with multiple inheritance. It is perceived as merely a convention (well in  only methods, in  also fields, in interfaces only the abstract methods, at multiple inheritance all is possible). It is valid so or I miss something important?

6

Re: and linearization

Hello, x-code, you wrote: XC> In Wikipedia any turbid difference between  and  and whether generally not clearly is a difference with multiple inheritance. It is perceived as merely a convention (well in  only methods, in  also fields, in interfaces only the abstract methods, at multiple inheritance all is possible). It is valid so or I miss something important? So the difference as a matter of fact also is not present between  and  (still there are roles). More precisely each language can add itself any context-sensitive difference, and can, and the functional difference. For example in some objective systems Perl is  and roles which are same, are equally implemented, but this or that title is used depending on a context. The difference with multiple inheritance consists that  "are not visible" as ancestors of a class if language allows to lead such .

7

Re: and linearization

Hello, x-code, you wrote: XC> I Read some books on Scala and there new entities -  (traits) and "new type of inheritance" - linearization are entered. XC> but something not so I understand all it. XC> and who  can explain on fingers, in particular as it is arranged on a low level, well and generally. XC> With normal inheritance all is quite clear, and in general it is possible to tell that it is low-level enough mechanism (if there there is no virtuality) - the base class simply turnes on in derivative as its part. And how are arranged ? In JVM there is a concept "interface", it is a dial-up  methods (well or a class with the abstract methods if to speak on-sipljuspljusi). The class in JVM can be inherited from one class and set of interfaces. On it also are constructed all . The main counter that if in  there is a property  the getter-setter really there is declared, and then at inheritance of it  is interposed into a class a field and these gettery-setters by access to this field are implemented. That's all, basically. Anything difficult actually.

8

Re: and linearization

Hello, vsb, you wrote: vsb> In JVM there is a concept "interface", it is a dial-up  methods (well or a class with the abstract methods if to speak on-sipljuspljusi). The class in JVM can be inherited from one class and set of interfaces. On it also are constructed all . The main counter that if in  there is a property  the getter-setter really there is declared, and then at inheritance of it  is interposed into a class a field and these gettery-setters by access to this field are implemented. That's all, basically. Anything difficult actually. And how the problem of diamond-shaped inheritance there dares? After all as I understood, difference  in Scala from interfaces in that that in them can be not only abstract, but also specific fields.

9

Re: and linearization

Hello, x-code, you wrote: XC> And how the problem of diamond-shaped inheritance there dares? After all as I understood, difference  in Scala from interfaces in that that in them can be not only abstract, but also specific fields. Specific fields in  cannot be, JVM such not . The specific field appears in a class which implements . In what a problem of diamond-shaped inheritance? Probably better simply to hammer an example and to look that happens.

10

Re: and linearization

Hello, x-code, you wrote: XC> And how the problem of diamond-shaped inheritance there dares? After all as I understood, difference  in Scala from interfaces in that that in them can be not only abstract, but also specific fields. The problem of diamond-shaped inheritance is there where access to fields is admitted directly (a C ++), and not just through gettery/setters, as in the Rock. The code generated in them the compiler for the lower node of a rhomb, just depends on the mechanism linearization. trait Foo {var vr: String = ""; val v: String; def foo (): String} trait A extends Foo {vr = "vrA"; override val v = "vA"; override def foo () = "fooA"} trait B extends Foo {vr = "vrB"; override val v = "vB"; override def foo () = "fooB"} println (List (new B with A {}, new A with B {}).map (x => (x.v, x.vr, x.foo))) - - List ((vA, vrA, fooA), (vB, vrB, fooB))