Scala has a number of traits that you can use as type classes, for example Ordered
and Numeric
in the package scala.math
.
I can, f
Ordered
is just a few simple pimped methods that return either Int
or Boolean
, so no type-trickery is needed.
Numeric
, on the other hand, has methods that return different types depending on the exact subclass used. So while Ordered
is little more than a marker trait, Numeric
is a fully-featured type class.
To get your operators back, you can use mkNumericOps
(defined in Numeric
) on the lhs operand.
UPDATE
Miles is quite right, mkNumericOps
is implicit, so just importing that instance of Numeric will give you back all the magic...