$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] painless currying
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2011-08-25 02:29:28
Le 25/08/11 03:41, Joshua Juran a écrit :
> 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]()
>
I like it. This le us see a curryable as a fuctor that maps args to new
functors. Which operator could reflect better this mapping tahn the
subscript operator?
It solves the asymetric issue and the variadic one also.
Best,
Vicente