Boost logo

Boost :

Subject: Re: [boost] painless currying
From: Joshua Juran (jjuran_at_[hidden])
Date: 2011-08-24 21:41:45


On Aug 24, 2011, at 1:38 PM, Dave Abrahams wrote:

> I mean this, for a ternary function f:
>
> f(x) => doesn't call f
> f(x)(y) => doesn't call f
> f(x)(y)(z) => calls f
>
> That last step looks asymmetric to me.
>
> In a lazy language, f(x)(y)(z) *doesn't* call f... until you actually
> use the result for something... which is more consistent-looking.
>
> I suppose the symmetrical non-lazy version looks like:
>
> f(x) => doesn't call f
> f(x)(y) => doesn't call f
> f(x)(y)(z) => doesn't call f
> f(x)(y)(z)() => calls f

What about using [] for currying and () for calling?

f[x] => returns binary function
f[x][y] => returns unary function
f[x][y][z] => returns nullary function

All of these have the same effect:

f(x, y, z)
f[x](y, z)
f[x][y](z)
f[x][y][z]()

Josh


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk