Created
January 4, 2013 15:59
-
-
Save devknoll/4453658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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