Use case for std.bind
downs
default_357-line at yahoo.de
Tue Feb 24 04:23:20 PST 2009
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
More information about the Digitalmars-d
mailing list