[phobos] D std.bind
Jason Spencer
spencer8 at sbcglobal.net
Thu Jun 17 09:55:47 PDT 2010
Andrei Alexandrescu <andrei at ...> writes:
>
> I wrote a curry in std.functional which I think could be a good starting
> point.
I'm new to D syntax, but if I read that right, std.curry just gives you
an alias to a function call of two variables that fills in one for
you. Deprecating bind would still leave holes for:
- Currying an arbitrary length parameter list
- storing a delegate to the curried function
- composing curries (could be replaced by previous 2 if done in a certain way)
- binding at arbitrary parameter indexes
and maybe a couple of other things. In short, bind gives support for all kinds of
partial applications, where as std.curry only allows picking off one arg in a
two-arg function. If bind were deprecated, is there a plan to replace the other
functionality?
Seems like with the new functional capabilities of D 2, bind is MORE
necessary, since I would imagine more higher order functions being
written and extended. If that's true, then there's gonna be an awful
lot of boiler plate code like:
auto p_2 = function ReturnType!plus (ParameterTypeTuple!plus[1] arg2,
ParameterTypeTuple!plus[2] arg3) { return plus(2, arg2, arg3); } ;
rather than
auto p_2 = bind(plus, 2, _0, _1);
I'd love to see partial applications supported in the language, but short of
that, I'd say there needs to be some easier way to curry in, say 5 argument
calls, or else the functional features of D really loose
power. Bind already provides that. Maybe it just needs a make-over?
Jason
More information about the phobos
mailing list