Created
July 31, 2018 14:43
-
-
Save Luiz-Monad/4ad70cb35b7c1b9991d97a4639eccc59 to your computer and use it in GitHub Desktop.
csharp fixpoint fib
This file contains hidden or 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
using System; | |
public class Program | |
{ | |
delegate T id<T>(T arg0); | |
static id<T> Y<T>(id<id<T>> f) | |
{ | |
//Y f = f ( Y f ) | |
return x => f(Y(f))(x); | |
} | |
static id<id<T>> _<T>(id<id<T>> f) { return f; } | |
public static void Main(string[] args) | |
{ | |
var fib = _<int>(f => n => n < 2 ? n : f(n - 1) + f(n - 2)); | |
Console.WriteLine(Y(fib)(5)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment