I'm trying to pimp the Tuple(2) class with addition and scala multiplication members, so that I can use them more easily as geometric 2D points. This is what I've got:
implicit class Point[+T: Numeric](val t: (T, T)) {
import Numeric.Implicits._
def _1 = t._1
def _2 = t._2
def +[V >: T](p: Point[V])(implicit ev: Numeric[V]) : (V,V) =
(ev.plus(t._1, p._1), ev.plus(t._2, p._2))
}
println((2, 3) + Point(5.0, 6.0))
This doesn't work (can't find ev
) presumably because strictly speaking Float
isn't a supertype of Int
- but there doesn't actually seem to be a weak-conformance-bound operator, and leaving it out entirely means I can't use ev.plus
anymore because it's expecting two values of the same type V
, not one of T
and one of V
.
How can I properly implement this code?