在 Scala 中,为什么一个 curried 函数可以很容易地直接传递给其他函数,但是在将它分配给一个函数时,val还需要部分应用它_?例如,给定两个函数:
def curried(a: Int)(b: Int) = a + b
def test(a: Int, f: Int => Int) = f(a)
我可以很容易地传递curried给test:
test(5, curried(5))
一切都很幸福。但是,如果我只是打电话curried(5),我会收到一个错误:
scala> curried(5)
<console>:9: error: missing arguments for method curried;
follow this method with `_' if you want to treat it as a partially applied function
              curried(5)
但是,如果我将调用更改为包含类型信息,它将起作用:
val 'curried: Int => Int = curried(5)
谁能解释不一致背后的原因,Scala编译器肯定可以推断出该函数是Int => Int在原始方法上给出了类型定义的吗?