Trying to follow this example (taken from scala in action) for creating generic sum function for all collections
trait Summable[A] { def plus(a1: A, a2: A): A def init: A } object IntSummable extends Summable[Int] { def plus(a1: Int, a2: Int): Int = a1 + a2 def init: Int = 0 } trait Foldable[F[_]] { def foldLeft[A](xs: F[A], m: Summable[A]) : A } implementing foldLeft like this works fine :
object ListFoldLeft extends Foldable[List] { def foldLeft[A](xs:List[A],m:Summable[A]) = xs.foldLeft(m.init)(m.plus) } however, however, although the foldLeft function accepts two parameters (xs:List[A],m:Summable[A]), we send them seperatly xs.foldLeft(m.init)(m.plus) and it works fine
but if I try to send them like this :
object ListFoldLeft extends Foldable[List] { def foldLeft[A](xs:List[A],m:Summable[A]) = xs.foldLeft(m.init,m.plus) } I get
<console>:18: error: too many arguments for method foldLeft: (z: B)(op: (B, A) => B)B xs.foldLeft(m.init,m.plus) why ?