Skip to content

Instantly share code, notes, and snippets.

@lambdaydoty
Created March 14, 2019 06:31
Show Gist options
  • Save lambdaydoty/3f5f9c093a484c90c35279c6fa3a5ce4 to your computer and use it in GitHub Desktop.
Save lambdaydoty/3f5f9c093a484c90c35279c6fa3a5ce4 to your computer and use it in GitHub Desktop.
const fact0 = t => n =>
(n === 0) ?
1 :
n * t(n - 1)
const fib0 = t => n =>
(n === 0) ?
1 :
(n === 1) ?
1 :
t(n - 1) + t(n - 2)
/*
* Curry's lazy version
*
* Y = f => (x => f(x(x)))
* ((x => f(x(x))))
*
* Do an Alpha conversion:
*
* Y = f => (g => f(g(g)))
* ((g => f(g(g))))
*
* Recall the inverse eta transformation:
*
* t(t) ----> x => t(t)x
*
*/
// Finally the strict version:
const Y = f => x => (g => f(x => g(g)(x)))
((g => f(x => g(g)(x))))(x)
console.log(
Y(fact0)(5)
)
for (let i = 0; i < 10; i++) {
console.log(
Y(fib0)(i)
)
}
for (let i = 0; i < 10; i++) {
console.log(
Y(fib0)(i)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment