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);
nested(nested)seems to give an error aswell - sharplab.io/…Ymethod doesn't except a delegate of typeYso that will be a type error. If you want to return a local function, you need to useFuncor define a delegate with the correct return type. What's wrong with the implementation here: stackoverflow.com/a/31821236/1462295 ?