I'd like to create a simple function:
def sum(a,b) = a + b
But then it won't compile, I have to do
def sum(a:Int, b:Int) : Int = a + b
Which is much longer to code and type-bound. Is it possible to do it without specifying the type, just as I'd do in OCaml:
let sum x y = x + y
aandb? the+operator can be applied to any two types.sum a b = a + bwould get a type likeforall a. Num a => a -> a -> a. This can be done because there we have no subtying and type classes are closed, which is both not the case in Scala.Int's and not twoString's?Numtypeclass. In Scala terms, something likesum[T](a: T, b: T)(implicit plusable: { def +(T, T): T }). If you later happen to applysumto anInt, then that's ok, because that's subsumed under the polymorphic type.