|
Boost : |
Subject: Re: [boost] painless currying
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-08-25 16:16:59
on Thu Aug 25 2011, Eric Niebler <eric-AT-boostpro.com> wrote:
> On 8/24/2011 6:15 PM, Dave Abrahams wrote:
>>
>> on Wed Aug 24 2011, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
>>
>>> Dave Abrahams wrote:
>>>
>>>> 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
>
> I simply don't see the problem with:
>
> f(x) ==> curry
> f(x, y) or f(x)(y) ==> curry
> f(x, y, z) or etc. ==> evaluate
>
> Can you say specifically what you think the problem is?
It just rubs me the wrong way that sometimes passing arguments to a
function has no execution semantics, but if you happen to complete an
argument list, suddenly it's called.
> This is how its done in Haskell, for instance (although Haskell
> doesn't use parens around argument lists).
Well, no, it's not exactly how it's done in Haskell, because in Haskell
f is lazy, and that's what makes the difference.
You probably know this, but I can pass:
(f x y z) -- which would be f(x, y, z) in C++
to another function that will then throw it away, and f will never be
invoked.
let oar x y = if x then x else y
if I invoke:
oar True (f x y z) -- analogous to oar(True,f(x y z)) in C++
You can prove this to yourself by invoking putStrLn in f.
>> Yes, it has always been my view that bind was unambiguously better
>> for non-lazy languages, and at least more flexible even for lazy
>> ones.
>
> Better and more flexible in what ways?
It's better because it avoids confusion about when things are invoked.
It's more flexible because it allows the 2nd argument to be bound before
the first argument is available.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk