Y-COMBINATOR-JS
derive the y combinator using pure javascript
The Y combinator discovered by Haskell B. Curry is an implementation of the fixed-point combinator in lambda calculus.It defined as:
- call by value:
λf.(λx.f(λn.x x n))(λx.f(λn.x x n))
- call by name:
λf.(λx.f(x x))(λx.f(x x))
so in ecmascript 2015, It can be implement by one line
;
Installation
using npm
npm install y-combinator-js
Usage
it won't decrease the computation complexity, so don't use it in production enviroment,unless you know what you do.
;
then enjoy it:
-
factorial
const FACT10 = 3628800;const fact = ;should; -
fibonacci
const FIB = 0 1 1 2 3 5 8 13 21 34 55 89 144;const fibonacci = ;should;should;
License
MIT