Scala 3's multiple inheritance is a bit different from Scala 2's. It feels quirky in the context of Scala 2, but the rules are easier to understand. Traits can now take parameters, but you're only allowed to apply them in the extends clause of a class (not another trait).
-
Show this thread
-
An inheritance hierarchy between traits will be "parameterless" inheritance, so the linearization order is not so significant, and the type system now provides a sound way to combine multiple transitive inheritances of the same trait (which may have different type parameters).
1 reply 0 retweets 2 likesShow this thread -
Class-to-class inheritance is always single-inheritance, so there's never any ambiguity when applying the value parameters, though there may still be a need to resolve conflicts in concrete implementations.
1 reply 0 retweets 0 likesShow this thread -
A new error will occur with code like this: trait Foo(x: Int) trait Bar extends Foo // not allowed to extend Foo(0)! class Baz() extends Bar We are told that we need to explicitly specify the inheritance of Foo with its parameter, like so: class Baz() extends Bar, Foo(0)
1 reply 0 retweets 2 likesShow this thread -
You also get to use commas to separate the list of inherited traits.
3 replies 0 retweets 2 likesShow this thread -
Replying to @propensive
I don't really understand the reason for trait parameters other then allowing context bounds / implicits on the type parameters. Also I was never find of extending case classes either. Something about it feels wrong. Like mixing types and values in the wrong way.
1 reply 0 retweets 0 likes -
Replying to @polaris_s0i @propensive
Would love to see a usecase that makes sense for this.
1 reply 0 retweets 0 likes -
Replying to @polaris_s0i
I think that an example would be any where you mixin a trait which has just one abstract def (and other members which depend on it) and you need to *implement* the abstract def, rather than just specifying it positionally.
1 reply 0 retweets 0 likes
That may make it sound unspectacular as a new feature, but that may be fair: it's more a "routine convenience" than a "dramatic enhancement".
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.