I am trying to figure out how to use currying in Scala.
In the following snippet:
object Foo {
def foo(a:Int)(b:Int)(c:Int) : Int = a + b + c
def main(a:Array[String]) {
val f = foo(1)(2) _
def g : Int => Int = foo(1)(2)
println(f(3))
println(g(3))
}
}
definitions are used for fand g, for hdoes not exist:
/home/vlad/Desktop/b.scala:9: error: missing arguments for method foo in object Main;
follow this method with `_' if you want to treat it as a partially applied function
def h = foo(1)(2)
What are the reasons for this illegal? It seems to me that Scala should be able to figure out that after the call foo(1)(2)you will be left with Int => Int.
source
share