Operators as function arguments?

Falk Henrich schreibmalwieder at hammerfort.de
Sat Mar 24 03:16:12 PDT 2007


Daniel Keep wrote:

> Like Chris said, there's really no way to get what you want in this
> case.  D is not Haskell, so we just have to make lots of delegates :P

I agree although I actually don't know Haskell that much, only Opal ([1]).

> Way back when I first started using D, I actually wrote up a bunch of
> templates that defined delegates for every unary and binary operator,
> and a bunch of templated tests (like less-than, equal-to, etc.).

That's what I'm doing now. It's like a yoga ;-)

> Re: your cat template above, you should be able to do this:
> b = reduce(a, &cat!(int));

Thanks. That makes the thing a bit less wordy.

> The way I look at functional programming in D is basically: It's not as
> good as a *real* functional programming language, but boy does it beat
> the pants off C/C++/Java/C#/etc.!

True. I think the ability to mix different paradigms in D is really good.
None of the pure functional languages will get widely accepted as there's
no decent I/O. On the other hand, things like HOF reduce code length and
bugginess by a factor. So it's a really good idea to get the good stuff
from FP without restricting to it.

>> [2] http://www.prowiki.org/wiki4d/wiki.cgi?DanielKeep/functools
> 
> Oh, you have no idea how much of a kick it is to see that link.  ^_^

It's a good example for D's "static if" and similar features.

Falk


[1] http://uebb.cs.tu-berlin.de/~opal/


More information about the Digitalmars-d-learn mailing list