Just wanted to know question w.r.t Currying
If we have defined the curried function 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)
^
So why does curriedNewSum(10)_ works & curriedNewSum(_)(10) not?
I’m not 100% sure what exactly is the problem, but I strongly suspect this isn’t doing what you think it is.
Try, for instance,
You’ll see it will return a
Function1[Int, Function1[Int, Int]]. Now try this:And see it work! Well, that translates into:
While the other way translates into:
Something about how the function is expanding is screwing up with the type inference.