Created
February 25, 2020 02:49
-
-
Save kylehovey/567c223ae933408e25f7165a50ea1c33 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
const mkWrapper = () => ( | |
cache => f => n => n in cache | |
? cache[n] | |
: cache[n] = f(n) | |
)([]); | |
const M = f => f(f); | |
const Y = f => ( | |
wrapper => M( | |
maker => n => wrapper( | |
f(M(maker)) | |
)(n) | |
) | |
)(mkWrapper()); | |
const fact = Y(self => n => ( | |
console.log(n), | |
n <= 0 | |
? 1 | |
: n * self(n-1) | |
) | |
); | |
console.log(fact(6)); | |
console.log(fact(7)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment