Created
September 16, 2019 07:30
-
-
Save leeor/e0e2a98286522b5ffa7c6cbac49c6a8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
function factorial(n) { | |
return n === 0 ? 1 : n * factorial(n - 1) | |
} | |
const almostFactorial = f => n => n === 0 ? 1 : n * f(n - 1) | |
function tagY(fn) { | |
const z = _ => fn(y)(_) | |
const y = _ => fn(z)(_) | |
return z | |
} | |
function Y(f) { | |
function callsFunctionWithItself(x) { return x(x) } | |
function appliesSelfCallingLambda(x) { return f(y => x(x)(y)) } | |
return callsFunctionWithItself(appliesSelfCallingLambda) | |
} | |
factorial(3) | |
tagY(almostFactorial)(3) | |
Y(almostFactorial)(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment