I am studying the curried function of Scala but encountered the following question.
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>
Then, I looked into Scala's API (Function) and found that the object Function
does not have the method curried
. However, according to this post (Function Currying in Scala), it should work.
On the other hand, I also tried to transfer a curried function into un-curried one:
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
In this case, because uncurried
is a member of Function
, Function.uncurried(adder _)
is working. But this (adder _).uncurried
is not working instead.
Can anyone explain why it is designed like this in Scala? And