You can do this (with great difficulty) by creating implicit statements:
abstract class Arith[A,B,C] { def +(a: A, b: B): C def -(a: A, b: B): C def *(a: A, b: B): C def /(a: A, b: B): C } implicit object ArithIntLong extends Arith[Int,Long,Long] { def +(a: Int, b: Long) = a+b def -(a: Int, b: Long) = ab def *(a: Int, b: Long) = a*b def /(a: Int, b: Long) = a/b } ... def f[A,B,C](a: A, b: B)(implicit arith: Arith[A,B,C]) = arith.*(a,b) scala> f(5,10L) res46: Long = 50
but you really need to do more, because you only need the numerical equivalent for A and B, and asymmetric operations must be defined in both directions. And it is not very practical to specialize, given that there are three types.
source share