Created
October 21, 2012 18:35
-
-
Save takeshik/3928033 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
void Main() | |
{ | |
Make.Fix<int>(f => n => n < 2 ? 1 : f(n - 1) * n)(5).Dump(); // 120 | |
} | |
public class Make | |
{ | |
public static Func<T, T> Fix<T>(Func<Func<T, T>, Func<T, T>> func) { return Fun<T>.Fix(func); } | |
public static Func<T, T> Fix<T>(Func<Func<T, T>, Func<T, T>> func, T dummy) { return Fun<T>.Fix(func); } | |
private static class Fun<T> | |
{ | |
private delegate U SelfApplicable<U>(SelfApplicable<U> self); | |
private static SelfApplicable<Func<Func<Func<T, T>, Func<T, T>>, Func<T, T>>> Y = y => f => x => f(y(y)(f))(x); | |
public static Func<Func<Func<T, T>, Func<T, T>>, Func<T, T>> Fix = Y(Y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment