I'm trying to learn the Y-combinator better (I sort of understand it in Scheme) and implement it in D 2.0, and I'm failing pretty miserably:
auto fact = delegate(uint delegate(uint) recurse)
{
return delegate(uint n)
{
return n > 1 ? n * recurse(n - 1) : 1;
};
};
fact(fact)(5);
This doesn't work, for the obvious reason that I can't pass fact
to fact
(what would its type be?). And besides, I still need fact
's name to pass to itself, so it wouldn't work anyway, right?
But... how do I go about implementing the Y-combinator in D?
&
. – Vosges