Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- The Y combinator, discovered by Haskell B. Curry, is defined as: Y = \f.(\x.f (x x)) (\x. f (x x))
-- haskell
newtype Mu a = Mu (Mu a -> a)
y f = (\h -> h $ Mu h) (\x -> f . (\(Mu g) -> g) x $ x)
-- javascript
const factSource = partial => n => n === 0 ? 1 : n * partial(n - 1);
// Y Combinator: Y = \f. (\x. f (x x)) (\x. f (x x))
y = f => ( x => n => f(x(x))(n) )(
x => n => f(x(x))(n) );
const fac = y(factSource);
// OR
const Y = f => (x => x(x))(x => f(y => x(x)(y)));
const factorial = f => (x => (x === 1 ? 1 : x * f(x - 1)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment