Created
December 2, 2021 02:30
-
-
Save cauefcr/5413fd78a2a6d8be6b64cd423a1cdf42 to your computer and use it in GitHub Desktop.
Church numerals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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