Skip to content

Instantly share code, notes, and snippets.

@Luiz-Monad
Created July 31, 2018 14:43
Show Gist options
  • Save Luiz-Monad/4ad70cb35b7c1b9991d97a4639eccc59 to your computer and use it in GitHub Desktop.
Save Luiz-Monad/4ad70cb35b7c1b9991d97a4639eccc59 to your computer and use it in GitHub Desktop.
csharp fixpoint fib
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