部分应用函数作为对象

时间:2016-03-22 07:50:54

标签: scala currying

def f(i:Int)(j:Int) = i + j

等等

f(1) _
Int => Int = <function1>

然而,

val f: (Int)(Int) => Int = (a:Int)(b:Int) => a + b  // wrong

error: ';' expected but '(' found.如何声明val f

1 个答案:

答案 0 :(得分:2)

这是你在找什么?

scala> val f: Int => Int => Int = a => b => a + b
f: Int => (Int => Int) = <function1>

scala> f(1)
res7: Int => Int = <function1>

scala> f(1)(2)
res8: Int = 3