scala - Why does leaving the dot out in foldLeft cause a compilation error? -
can explain why see compile error following when omit dot notation applying foldleft
function?(version 2.9.2)
scala> val l = list(1, 2, 3) res19: list[int] = list(1 ,2 ,3) scala> l foldleft(1)(_ * _) <console>:9: error: int(1) not take parameters l foldleft(1)(_ * _) ^
but
scala> l.foldleft(1)(_ * _) res27: int = 6
this doesn't hold true other higher order functions such map
doesn't seem care whether supply dot or not.
i don't think associativity thing because can't invoke foldleft(1)
it's because foldleft curried. using dot notation, can fix adding parentheses:
scala> (l foldleft 1)(_ * _) res3: int = 6
oh - , regarding comment not being able invoke foldleft(l)
, can, need partially apply this:
scala> (l foldleft 1) _ res3: ((int, int) => int) => int = <function1>
Comments
Post a Comment