Skip to content

Instantly share code, notes, and snippets.

@devknoll
Created January 4, 2013 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devknoll/4453658 to your computer and use it in GitHub Desktop.
Save devknoll/4453658 to your computer and use it in GitHub Desktop.
delegate Func<T1, T2> Recursive<T1, T2>(Recursive<T1, T2> r);
public static Func<T1, T2> Y<T1, T2>(Func<Func<T1, T2>, Func<T1, T2>> f)
{
return ((Recursive<T1, T2>)(g => n => f(g(g))(n)))(
g => n => f(g(g))(n));
}
var fact = Y<int, int>(partial => n => n == 0 ? 1 : n * partial(n - 1));
Console.WriteLine(fact(5)); // Prints 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment