Use case for std.bind

Yigal Chripun yigal100 at gmail.com
Tue Feb 24 04:58:18 PST 2009


downs wrote:
> Yigal Chripun wrote:
>> Lars Kyllingstad wrote:
>>> I've always thought currying was the main point of std.bind. If I'm not
>>> mistaken, currying is commonly a built-in feature of functional
>>> programming languages, so if anything, std.bind could become more
>>> useful/important in D2 than in D1.
>>>
>>> I agree that the std.bind API could and should be improved.
>>>
>>> -Lars
>> you don't need bind for currying, it's even possible to do this in C:
>>
>> int foo(int a, int b) { ... }
>> int bar(int a) { return foo(a, _value); } // curry with some _value
>>
>> Other languages provide useful syntax sugar for currying:
>> auto bar2 = foo(_, 500);
>>
>> bar2 here will be a delegate that will do the the same as the above bar.
>
> Just for comparison' sake:
>
> auto dg =&foo /rfix/ somevar;			// 1.0, tools
> auto dg = _bind(&foo, _1, somevar);		// 1.0, std.bind
> auto dg = (int a) { return foo(a, somevar); };	// 2.0, literal
   auto dg = foo(_, somevar);

So does that mean you like the above suggestion?
after all, it's shorter and clearer than all the other alternatives.. ;)






More information about the Digitalmars-d mailing list