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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -