I wrote a trait for sorting iterables in Scala, and it took almost as long to make a class that I could mix it in with as it took to write the trait. Why was the design decision made to disallow users from writing things like:
new List[Int] with SuperAwesomeTrait[Int]?
Now if I want to do this, I need to do some weird hack like,
class StupidList extends LinearSeq {
val inner = List()
/* reimplement list methods by calling into inner */
}
and then
new StupidList[Int] with SuperAwesomeTrait[Int].
Because if I write
someList match {
case Cons(head, tail) => whatever
case Nil => somethingElse
}
I don't want my logic broken by a new, unexpected subclass.
I suspect you're trying to solve a problem using subclassing that would be better solved with implicits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With