[plt-scheme] Multiple values

From: Jim Blandy (jimb at red-bean.com)
Date: Tue Feb 21 13:13:44 EST 2006

On 2/21/06, Bill Wood <william.wood3 at comcast.net> wrote:
> Isn't it interesting that the MLr's got symmetry as a side-effect of
> supporting currying:  Currying requires that functions have only one
> argument, so they say that multiple-arg functions are in fact single-arg
> functions with the arg being a tuple.  So they have the symmetry that
> functions take tuples and return tuples, and they seem to be happy.

Yeah!  I love the theory of ML.  I just don't like actually using it. 
I wish I understood why.  I think most of my code would type-check
under an ML-like type system anyway, so I don't think it's the

As far as one-argument functions go: one of the fun things to watch
for is the conflict between these two favorite rules:

- "All you need are functions that take a single argument --- you can curry!"
- "All you need are tail calls --- you can transform into
continuation-passing style!"

I was very excited when I realized that you can't do both at once. 
You can start with this, say:

    (lambda (x) (+ x 1))

and then CPS to this:

    (lambda (x k) (k (+ x 1)))

(pretend that + is some sort of primitive, calls to which don't need
to be transformed) and then curry to this:

    (lambda (x) (lambda (k) (k (+ x 1))))

but then in order to actually use that (call it F), you need to write:

   ((F 3) (lambda (result) ... do something with the answer ...))

but then that (F 3) isn't a tail call!  So CPS requires functions that
take multiple arguments, and currying requires functions that take an
implicit continuation argument.

So if you wanted to be super-picky, you could say that ML functions
actually take *two* arguments: the one which could be a tuple of
arguments or whatever, and the invisible continuation.

Posted on the users mailing list.