title: Defining a trait with a method that return a value of different numeric type
body: <p>I have several classes that contains a numeric value (that value can be bounded, can be only positive, aso...)</p>
  
  <p>I must make some basic operations (like summing) based on a 'supertype' of those classes. So I defined a trait for it thinking it's gonna be trivial...</p>
  
  <p>Here is a runnable excerpt of my code :</p>
  
  <pre><code>object Main extends App {
  
    trait WithValue[A] {
      def value: A
    }
  
    class BoundedNumber[A](val lower: A, val upper: A, val value: A) extends WithValue[A]
  
    case class NumberBetween0and99(value: Int) extends BoundedNumber[Int](0, 99, value)
    case class UnboundedPositiveInt(value: Int) extends WithValue[Int]
    case class UnboundedPositiveDouble(value: Double) extends WithValue[Double]
  
  
    override def main(args: Array[String]) {
      val map: Map[Symbol, WithValue[_]] = Map(
        'foo -&gt; UnboundedPositiveDouble(5),
        'bar -&gt; UnboundedPositiveInt(10),
        'baz -&gt; NumberBetween0and99(55)
      )
      for (m &lt;- map) println(5 + m._2.value)
    }
  }
  </code></pre>
  
  <p>The for loop fail : </p>
  
  <pre><code>overloaded method value + with alternatives: (...) cannot be applied to (Any)
  </code></pre>
  
  <p>I am running in circle with this really trivial problem for some hours... guess my fluency in Scala is far from 'fluent'...</p>