Alternative Y combinator definition

后端 未结 3 539
轻奢々
轻奢々 2021-02-06 02:21

I\'ve spent some time wrapping my head around the Y combinator lately, and I\'ve found that it is usually defined (more or less) as follows (this is in C#, but the language of c

3条回答
  •  被撕碎了的回忆
    2021-02-06 02:37

    I’m not sure what your question is but I guess the reason that neither the Y combinator nor your solution are seen much in the wild is twofold:

    1. anonymous recursive functions are really rare; in particular since C# doesn’t have great (read: none at all) support for tail recursion.

    2. There’s a much easier (more readable for the uninitiated) way of defining pseudo-“anonymous” recursive lambdas in C#:

      Func fac = null;
      fac = x => x == 0 ? 1 : fac(x - 1) * x;
      

      Granted, this is not anonymous but it’s “close enough” for practical purposes.

提交回复
热议问题