Skip to content

Instantly share code, notes, and snippets.

@leeor
Created September 16, 2019 07:30
Show Gist options
  • Save leeor/e0e2a98286522b5ffa7c6cbac49c6a8f to your computer and use it in GitHub Desktop.
Save leeor/e0e2a98286522b5ffa7c6cbac49c6a8f to your computer and use it in GitHub Desktop.
'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