功能只是没有问题 - Scala?

时间:2016-07-12 08:46:16

标签: scala function currying

我正在研究Scala的curry函数,但遇到了以下问题。

scala> def add(x: Int, y: Int): Int = x + y
add: (x: Int, y: Int)Int

scala> val addCurried = Function.curried(add _)
<console>:11: error: value curried is not a member of object Function
       val addCurried = Function.curried(add _)

scala> val addCurried = (add _).curried
addCurried: Int => (Int => Int) = <function1>

然后,我查看了Scala的API(Function),发现对象Function没有方法curried。但是,根据这篇文章(Function Currying in Scala),它应该有效。

另一方面,我也尝试将一个咖喱功能转移到一个没有咖喱的功能中:

scala> def adder(x:Int)(y:Int): Int = x + y
adder: (x: Int)(y: Int)Int

scala> val addUncurried = Function.uncurried(adder _)
addUncurried: (Int, Int) => Int = <function2>

scala> val addUncurried = (adder _).uncurried
<console>:11: error: value uncurried is not a member of Int => (Int => Int)
       val addUncurried = (adder _).uncurried

在这种情况下,由于uncurriedFunction的成员,Function.uncurried(adder _)正在运作。但是这个(adder _).uncurried并没有起作用。

任何人都可以解释为什么在Scala中这样设计?并且

0 个答案:

没有答案