Skip to content

Instantly share code, notes, and snippets.

@infinnie
Created March 29, 2019 01:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinnie/25689f4ea20d4d9430ebf7f6c320ffe5 to your computer and use it in GitHub Desktop.
Save infinnie/25689f4ea20d4d9430ebf7f6c320ffe5 to your computer and use it in GitHub Desktop.
Fixed Point Combinator in C#
using System;
namespace ConsoleApp1
{
class Program
{
delegate T Out<T>(T x);
delegate Out<T> RecOut<T>(RecOut<T> x);
class YClass<T>
{
public static Out<T> Y (Out<Out<T>> g) {
RecOut<T> callIt = x => x(x);
return callIt(x => y => g(x(x))(y));
}
}
static void Main(string[] args)
{
Console.WriteLine(YClass<int>.Y(f => x => x == 0 ? 1 : x * f(x - 1))(6));
Console.ReadLine();
}
}
}
@Starr79
Copy link

Starr79 commented Mar 19, 2023

@Starr79
Copy link

Starr79 commented Mar 19, 2023

Beautiful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment