Use case for std.bind

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Feb 24 08:09:06 PST 2009


Daniel Keep wrote:
> The problem I have with these suggestions are that you're basically
> arguing for an incredibly inflexible, context-dependant, completely
> unintuitive syntax for something you already have working syntax for.  I
> just don't see the point.

I'd agree that generally there's a strong bias in this group for adding 
to the language. Every itsy-bitsy issue comes around, there are a dozen 
cute syntaxes invented for it right on the spot. And then once every few 
months, there's the inevitable huge thread "Where did my simple language 
go???" :o)

Currying/binding can be done easily with a library, and the 
implementation is so simple there's no need for a separate file 
dedicated to it. The one interesting case is currying a function passed 
by alias. In that case there's no indirect call, just a little struct 
created that contains the curried state:

int plus(int x, int y} { return x + y; }
auto plus5 = curry!(plus)(5);
assert(plus5(10) == 15);

typeof(plus5) will be a little struct that may be cumbersome to pass 
around, in which case you do want to take the toll of the indirect call 
by writing:

auto plus5 = makeDelegate(curry!(plus)(5));
assert(is(typeof(plus5) == int delegate(int));
assert(plus5(10) == 15);

This stuff belongs to std.functional. I plan to eliminate std.bind and 
put currying and binding in std.functional. What do people think?

Andrei



More information about the Digitalmars-d mailing list