Why does currying in Scala require multiple parameter lists?


Suppose I have a function of 2 parameters that I need to apply partially, I need to define it as:

def f(a: Int)(b: Int) = { /* some code */ }

And then I can apply it partially as def fWithA = f(a) _

My question is: In order to curry a function why does Scala require that the parameters are declared using multiple parameter lists? It would be preferable to be able to curry any function as desired.

A few reasons 'real' currying requires multiple parameter lists in Scala:

  • overloading. Unlike purely functional languages, in Scala you can overload methods. If you partially apply a function, the compiler may not be able to distinguish which overload you mean. The specification limits overloading resolution to the first parameter list.

  • error messages. "not enough arguments for method call" is a very useful (and easy to understand) error message. If one allowed currying for any method, the error message would be "required: but "some function type with many arrows" type.

  • performance. Running on the JVM makes it very efficient to call methods, while functions (going through an interface call) are slower.