Skip to content

Instantly share code, notes, and snippets.

@noghartt
Created September 30, 2021 03:11
Show Gist options
  • Save noghartt/d6e6564b50fc98067bc2544327f7df24 to your computer and use it in GitHub Desktop.
Save noghartt/d6e6564b50fc98067bc2544327f7df24 to your computer and use it in GitHub Desktop.
Church Numerals with JavaScript
const TRUE = x => y => x;
const FALSE = x => y => y;
const zero = f => x => x;
const succ = n => f => x => f(n(f)(x));
const plus = m => n => f => x => m(f)(n(f)(x));
const mult = m => n => f => x => m(n(f))(x);
const exp = m => n => n(m);
const pred = n => f => x => n(g => h => h(g(f)))(u => x)(u => u);
const minus = m => n => n(pred)(m);
const one = succ(zero);
const two = succ(one);
const three = plus(two)(one);
const four = plus(two)(two);
const five = plus(two)(three);
const six = mult(two)(three);
const seven = plus(three)(four);
const eight = mult(four)(two);
const nine = plus(five)(four);
const ten = mult(five)(two);
plus(one)(one);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment