title: Scala - extensions with Traits
body: <p>I am trying to understand how Odresky has apply (in an example) the extensions of applications in functionality through using Traits and here is the code: </p>
  
  <pre><code>trait Base {
    type exp &lt;: Exp
  
    trait Exp {
      def eval: Int
    }
  
    class Num(v: Int) extends Exp {
      val value = v
      def eval = value
    }
  }
  
  trait BasePlus extends Base {
    class Plus(l: exp, r: exp) extends Exp {
      val left = l
      val right = r
      def eval = left.eval + right.eval
    }
  }
  
  trait BaseNeg extends Base {
    class Neg(t: exp) extends Exp {
      val term = t
      def eval = -term.eval
    }  
  }
  
  trait Show extends Base {
    type exp &lt;: Exp
  
    trait Exp extends super.Exp {
      def show: String
    }
  
    class Num(v: Int) extends super.Num(v) with Exp {
      def show = value.toString()
    }
  }
  
  trait BasePlusNeg extends BasePlus with BaseNeg
  
  trait ShowPlusNeg extends BasePlusNeg with Show {
    class Plus(l:exp, r: exp) extends super.Plus(l, r) with Exp {
      def show = left.show + "+" + right.show
    }
    class Neg(t: exp) extends super.Neg(t) with Exp {
      def show = "-(" + term.show + ")"
    }
  }
  
  
  trait DblePlusNeg extends BasePlusNeg {
    type exp &lt;: Exp
  
    trait Exp extends super.Exp {
      def dble: exp
    }
  
    def Num(v: Int): exp
    def Plus(l: exp, r: exp): exp
    def Neg(t:exp): exp
  
    class Num(v: Int) extends super.Num(v) with Exp {
      def dble = Num(v * 2)
    }
    class Plus(l: exp, r:exp) extends super.Plus(l, r) with Exp {
      def dble = Plus(left.dble, right.dble)
    }
    class Neg(t: exp) extends super.Neg(t) with Exp {
      def dble = Neg(t.dble)
    }
  }
  
  trait ShowDblePlusNeg extends ShowPlusNeg with DblePlusNeg {
    type exp &lt;: Exp
    trait Exp extends super[ShowPlusNeg].Exp with super[DblePlusNeg].Exp
    class Num(v: Int) extends super[ShowPlusNeg].Num(v) with super[DblePlusNeg].Num(v) with Exp //error
    class Plus(l: exp, r: exp) extends super[ShowPlusNeg].Plus(l, r) with super[DblePlusNeg].Plus(l, r) with Exp //error
    class Neg(t: exp) extends super[ShowPlusNeg].Neg(t) with super[DblePlus.Neg].Neg(t) with Exp //error
  }
  </code></pre>
  
  <p>The last three mixings will not compile because </p>
  
  <pre><code> Multiple markers at this line
      - traits or objects may not have parameters
      - class Num needs to be a trait to be mixed in
  </code></pre>
  
  <ul>
  <li>I am guessing that it is implemented with the previous versions of Scala 1.4 but anyway a class never has been able to offer mixing, nor in previous versions. How I can mix without the need to change the classes in Traits?</li>
  </ul>