0

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); 
3
  • nested(nested) seems to give an error aswell - sharplab.io/… Commented Dec 28, 2022 at 7:18
  • How about post full code Commented Dec 28, 2022 at 7:36
  • Your Y method doesn't except a delegate of type Y so that will be a type error. If you want to return a local function, you need to use Func or define a delegate with the correct return type. What's wrong with the implementation here: stackoverflow.com/a/31821236/1462295 ? Commented Dec 28, 2022 at 16:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.