1

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

fluency03
  • 2,637
  • 7
  • 32
  • 62
  • 3
    You are looking at the post from 2008. Find something newer. Curried has been deprecated 6 years ago already: http://stackoverflow.com/questions/3568002/scala-tuple-unpacking – michaJlS Jul 12 '16 at 09:57

0 Answers0