|
Boost : |
Subject: Re: [boost] painless currying
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-08-26 14:05:48
on Fri Aug 26 2011, Eric Niebler <eric-AT-boostpro.com> wrote:
> On 8/26/2011 1:10 PM, Dave Abrahams wrote:
>>
>> Yeah... but in C++ we generally distinguish nullary functions from their
>> results, and we generally care when things are invoked.
>
> That's true. But nobody wants to curry a nullary function, so I guess
> you're arguing by extension that we should likewise be concerned about
> potential confusion when more arguments are involved. And I still don't
> see what is confusing about it. Can you give an example where plausible
> code gives surprising results because of implicit currying instead of
> explicit binding?
When the function object takes a variable number (or two different
numbers) of arguments, it's not clear when you're supposed to invoke it.
>>>>>> 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.
>>>
>>> Meh.
>>
>> That's an argument?
>
> About as convincing an argument as "it rubs me the wrong way." ;-)
My argument, though subjective and aesthetic, at least is not
content-free: I describe what about the situation gives me the willies.
> Eric Niebler wrote:
>> I don't see any technical obstacles to:
>>
>> f(_, y, z)
>>
>> where _ is a placeholder. You could use positional placeholders for
>> argument reordering.
That's more general than straight currying, and it's clearer: f(x,_,_)
is a curried version of f that is a bit more explicit about what it
means than just writing f(x).
> You might say the syntactic advantages of this over bind(f, _, y, z) are
> minimal. You might be right.
I wouldn't say that. I like the placeholder syntax; it's similar to
what MPL does, and frankly I had assumed we already had libraries
(phoenix?) that did things this way. The only question is what happens
when you write f(x,y,z). IIUC, phoenix leaves you with a nullary
function, but you're proposing to actually call f. I'm just not sure
that's quite as appropriate in C++ as it is in Haskell. Suppose you
*wanted* a nullary function object (e.g. so you could launch a thread
with it) rather than its result. Then you need to switch to a different
syntax for the final argument?
-- 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