[plt-scheme] Why do layman programmers care about Currying?

From: Henk Boom (lunarc.lists at gmail.com)
Date: Tue Dec 30 23:31:32 EST 2008

2008/12/30 Grant Rettke <grettke at acm.org>:
> Why do layman (working programmers) care about Currying? Or how are
> they applied in daily use to help one out?
> http://en.wikipedia.org/wiki/Currying

I find currying is useful as an alternative of (or at least
alternative syntax for) small anonymous lambdas. This gets used more
often in Haskel, but digging through some Scheme code I wrote for a
compiler design class, here's a really simple example.

; process a class definition
(define (process-class class)
  (for-each (curry process-function class) (defn:class-methods class)))

This code in particular traverses a class definition from the parse
tree, with the eventual aim of filling in things like labels to use
for function addresses in the generated assembly. Here
process-function needs the class definition as context for function
processing, so I provide it as the first argument. Using curry just
gives me a convenient way to fix the first argument. I could have used
(lambda (f) (process-function class f)), but I find curry clearer.
Also, lambda expressions like that one are less practical for
functions which take more arguments, or even keyword arguments.

But this is just my use, maybe someone else can come up with something
more interesting. =)


Posted on the users mailing list.