def f(x: Int)(y: Int) = x + y
和 和有什么不一样def f(x: Int) = (y: Int) => x + y
?
当我将前者与后者一样对待时,REPL 似乎并不高兴:
scala> def f(x: Int)(y: Int) = x + y
f: (x: Int)(y: Int)Int
scala> f(42)
<console>:9: error: missing arguments for method f;
follow this method with `_' if you want to treat it as a partially applied function
f(42)
^
scala> def f(x: Int) = (y: Int) => x + y
f: (x: Int)Int => Int
scala> f(42)
res2: Int => Int = <function1>
确切的区别是什么?我什么时候应该使用哪种形式?