关于curried函数的问题
只是想知道问题w.r.t Currying
如果我们已经定义了curried函数curriedNewSum
scala> def curriedNewSum(x : Int)(y : Int) = x + y
curriedNewSum: (x: Int)(y: Int)Int
scala> curriedNewSum(10)(20)
res5: Int = 30
scala> var tenPlus = curriedNewSum(10)_
tenPlus: (Int) => Int = <function1>
scala> tenPlus(20)
res6: Int = 30
scala> var plusTen = curriedNewSum(_)(20)
<console>:6: error: missing parameter type for expanded function ((x$1) => curri
edNewSum(x$1)(20))
var plusTen = curriedNewSum(_)(20)
^
那么为什么curriedNewSum(10)_工作&amp; curriedNewSum(_)(10)不?
没有找到相关结果
已邀请:
3 个回复
蓟类
你会看到它会返回一个
。现在试试这个:
看到它的工作!嗯,这转化为:
而另一种方式转化为:
关于函数如何扩展的一些东西搞砸了类型推断。
青董据零
哪一个会被选中?明确定义类型说明您想要的方法。
悍蕾驮苇袜