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

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Thu Jan 1 17:31:30 EST 2009

On Wed, Dec 31, 2008 at 5:55 PM, Gregory Woodhouse
<gregory.woodhouse at gmail.com> wrote:
>  Isn't the point of using monads....

I'm not a real fan of monads, but the original idea was to take a program that
operated on base types, like int -> int, and transform it to a program that
operated on (f int) -> (f int).  In this new space, you can plug the elements
together to create a program that operates on ints, but is explicitly `wired'
to behave in a certain way.

 For example, you can mimic state by passing around a state variable.
You tranform your int -> int functions to (f int state) -> (f int
state), plug the
transformed functions together linearly so the state variable behaves
correctly, then run the resulting program.

I'm sure you've done something similar with Scheme programs by
passing around an accumulator or something.

Now here's the magic part.  If you look at the transformed code, you'll
see that the bulk of it isn't really using the state variable, it is simply
passing it along to the next guy.  So move the state variable to the end
of the argument list, *curry the function*, and voila!  the state variable
is gone!  You can do this to most of the code and make the state
variable virtually disappear.

What you've done is factored your code such that the `plumbing'
--- the state variable and associated argument passing --- can be
separated from the more interesting computation.

The step of moving the state variable to the end of the argument list
and currying is critical.  The trick wouldn't be nearly as interesting
if you couldn't drop the curried variable out of the picture.  In Scheme,
this is a bit of a pain because currying the argument list means
changing *every* call site.  In Haskell, however, you can simply
omit the required variable and the language takes care of it.

That's why I said that the Haskell community would be far less
excited about monads if their language didn't automagically do the


Posted on the users mailing list.