Skip to content

Instantly share code, notes, and snippets.

@cauefcr
Created December 2, 2021 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cauefcr/5413fd78a2a6d8be6b64cd423a1cdf42 to your computer and use it in GitHub Desktop.
Save cauefcr/5413fd78a2a6d8be6b64cd423a1cdf42 to your computer and use it in GitHub Desktop.
Church numerals
const R = require("ramda");
//church encoding
let _0 = fn => x => x;
let _1 = fn => x => fn(x);
let _2 = fn => x => fn(fn(x));
let _3 = fn => x => R.pipe(...R.repeat(fn,3))(x);
let _256 = [_0,_1,_2,_3,...R.range(4,256).map(z => fn => x => R.pipe(...R.repeat(fn,z))(x))];
//R.range(0,256).map(x => {
// console.log(_256[x](n => n+1)(0));//boom, mind blown
//});
let sum = fn => m => n => _256[m](fn)(n);
console.log(sum(n=>n+1)(1)(10)); //nice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment