Trying to setup y combinator using C# delegate type

68 Views Asked by At

I am trying to write Y combinator as C# delegate so I can understand the types but I am failing. I appreciate any help or hint.

Rec<T> Y<T>(ToRec<T> f)
{
    Rec<T> nested(Rec<T> x)
    {
        return f(x(x));
    }
    
    return nested(nested);
}

Y<string>(Y);  // This line doesn't type check

delegate Rec<T> ToRec<T>(T x);
delegate T Rec<T>(Rec<T> x);
0

There are 0 best solutions below