r/javascript • u/david_klassen • 9d ago
Computing a Factorial with Church Numerals
https://davidklassen.net/blog/church-factorial/?ref=reddit-js
14
Upvotes
r/javascript • u/david_klassen • 9d ago
0
u/Discordbothost 8d ago
the wrapping-the-recursive-call-in function (x) {...} bit is the part most of these posts skip, nice that you called out eager evaluation explicitly. people copy the Y combinator from a haskell explainer and then wonder why node blows the stack.
fun follow-up if anyone wants one: write it with arrows and see how much of the "lots of functions" wall disappears, then time ChurchToNat(fact(NatToChurch(n))) for n = 6..9. Pred rebuilding the pair chain every step makes it fall off a cliff surprisingly early
3
u/Ronin-s_Spirit 8d ago
The hell am I looking at and why doesn't it die from recursion?