How to solve expression problem in Scala 3 with single class inheritance?

Here in this article
http://lampwww.epfl.ch/~odersky/papers/ExpressionProblem.html
was proposed solution to the expression problem.

But there is a problem implementing it in Scala 3.
The last part:

use multiple class inheritance.
Can we implement it in Scala 3 somehow?

It says:

The code in that paper was written for Scala version 1; it does not compile under Scala version 2. The following two files contain the updated version:

I looked at this file: https://lampwww.epfl.ch/~odersky/papers/abstract-data-mixin.scala and it’s different than the screenshot you have (which I assume is from the paper, which had Scala 1). Here traits are used instead of classes:

trait ShowDblePlusNeg extends ShowPlusNeg with DblePlusNeg {
  type exp <: Exp

  trait Exp extends super[ShowPlusNeg].Exp with super[DblePlusNeg].Exp

  trait Num
    extends super[ShowPlusNeg].Num
       with super[DblePlusNeg].Num
       with Exp

  trait Plus
    extends super[ShowPlusNeg].Plus
       with super[DblePlusNeg].Plus
       with Exp

  trait Neg
    extends super[ShowPlusNeg].Neg
       with super[DblePlusNeg].Neg
       with Exp
}
1 Like