Hi I've updated PEP309 a little, since someone sent me a better implementation. I haven't mentioned in the latest version the recent objection by Dave Abrahams that: Several languages have misused the term "curry" this way mostly on the grounds that the main language using curry that way is English :) The first Google result I found that mentioned function currying was this: [ http://www.engr.uconn.edu/~jeffm/Papers/curry.html ] Function Currying in Scheme I'll quote from the abstract: Function currying is the process of partially, or incrementally, supplying arguments to a function. Curried functions are delayed functions expecting the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally. I haven't the time for an exhausive statistical and linguistic analysis. My vote goes for the prevalent definition of currying that is actually a useful functional programming abstraction, i.e. the one described above. Anyway, this is my last request for flames about the presentation and content of the PEP itself before I post a full draft of the proposed 'functional' module. Peter Harris
I'll quote from the abstract: Function currying is the process of partially, or incrementally, supplying arguments to a function. Curried functions are delayed functions expecting the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally.
But there's a perfectly good term for that behavior: partial application, and what that note calls curried functions are really closures. If you use currying to refer to what I've just called partial application, what term do you use to refer to currying? I'm with Dave on this one: If you have a function f that takes two arguments, then currying f should yield a function with one argument that returns a function that takes one argument.
The first Google result I found that mentioned function currying was this: [ http://www.engr.uconn.edu/~jeffm/Papers/curry.html ] Function Currying in Scheme
I should have read the paper itself before commenting on it, because the paper uses the term correctly.
I'll quote from the abstract: Function currying is the process of partially, or incrementally, supplying arguments to a function. Curried functions are delayed functions expecting the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally.
Unfortunately, the abstract *does not* use the term correctly :-) More accurately, the abstract uses the term twice: once correctly, once incorrectly. Here's what the abstract should say: Function currying is the process of transforming a function that expects all of its arguments at once into a delayed function (called a curried function) that expects the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally. This revised abstract is consistent with the usage of the term "curried functions" in section 1 of the paper. Moreover, it is also consistent with the way in which the function "curry" behaves in section 3.
Andrew Koenig
I'm with Dave on this one: If you have a function f that takes two arguments, then currying f should yield a function with one argument that returns a function that takes one argument.
and then he wrote:
I'll quote from the abstract: Function currying is the process of partially, or incrementally, supplying arguments to a function. Curried functions are delayed functions expecting the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally.
Here's what the abstract should say:
Function currying is the process of transforming a function that expects all of its arguments at once into a delayed function (called a curried function) that expects the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally.
But isn't that just as wrong as the first version? It still seems to be describing partial application, not currying as you defined it above. Maybe it should say Function currying is the process of transforming a function that takes n arguments into a function that takes one argument and returns another function (itself also curried, if n > 2) that takes the remaining n-1 arguments. Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
Here's what the abstract should say:
Function currying is the process of transforming a function that expects all of its arguments at once into a delayed function (called a curried function) that expects the remainder of the arguments to be supplied. Once all the arguments are supplied, the function evaluates normally.
But isn't that just as wrong as the first version? It still seems to be describing partial application, not currying as you defined it above. Maybe it should say
Function currying is the process of transforming a function that takes n arguments into a function that takes one argument and returns another function (itself also curried, if n > 2) that takes the remaining n-1 arguments.
Actually, we're both wrong. I missed a level of indirection in trying to reuse words from the original abstract where possible, so I missed that the "delayed function" must itself return a function. You missed that the function returned takes only one argument, not n-1 arguments. Perhaps this way will work: Function currying is the process of transforming a function that expects all of its arguments at once into a delayed function (called a curried function), that expects only its first argument. If the first argument is the only argument, currying is the identity function. Otherwise, the delayed function, itself also curried, expects the first of the remaining arguments and yields either the result (if there is only one remaining argument) or a similarly delayed, curried function that deals with the second and subsequent remaining arguments.
On Monday 2004-02-23 16:06, Andrew Koenig wrote:
Function currying is the process of transforming a function that expects all of its arguments at once into a delayed function (called a curried function), that expects only its first argument. If the first argument is the only argument, currying is the identity function. Otherwise, the delayed function, itself also curried, expects the first of the remaining arguments and yields either the result (if there is only one remaining argument) or a similarly delayed, curried function that deals with the second and subsequent remaining arguments.
I think it's better to define partical application and currying together, as follows. Partial application is a way of transforming a function by specifying values for some of its arguments. If f is a function of n arguments and 0 <= m <= n, then the partial application of f to y1,...,ym is a function f1 of n-m arguments such that f1(x(m+1),...,xn) = f(y1,...,ym, x(m+1),...,xn). Currying is a way of transforming a function so that instead of accepting all its arguments at once it accepts just the first, returning a function which accepts just the second, returning a function which accepts just the third, and so on. Formally, denote the partial application of f to y1,...,ym by f[y1,...,ym]; then currying is the function transformer C such that - when f is a function of no arguments, C(f) = f(); - when f is a function of at least one argument, C(f) is the 1-argument function taking y1 to C(f[y1]). Note that currying a no-argument function yields not a function but a constant; currying a 1-argument function yields the same function. It follows that C(f)(x1)(x2)...(xn) = f(x1,x2,...,xn). In a context where the definition of partial application isn't useful, this can be shortened to Currying is a way of transforming a function so that instead of accepting all its arguments at once it accepts just the first, returning a function which accepts just the second, returning a function which accepts just the third, and so on. Formally, given a function of at least one argument and a value y1, denote by f[y1] the function that takes (x2,...,xn) to f(y1,x2,...,xn). Then currying is the function transformer C such that - when f is a function of no arguments, C(f) = f(); - when f is a function of at least one argument, C(f) is the 1-argument function taking y1 to C(f[y1]). It follows that C(f)(x1)(x2)...(xn) = f(x1,x2,...,xn). Note that currying a no-argument function yields not a function but a constant; currying a 1-argument function yields the same function; currying any function with at least one argument yields a function that takes exactly one argument. I think it's elegant to start the definition at 0-argument functions, but obviously you can alternatively define currying only for functions of at least one argument, in which case you have the advantage that it always yields a function :-). -- g
participants (4)
-
Andrew Koenig
-
Gareth McCaughan
-
Greg Ewing
-
Peter Harris