Church encoding utility library for JavaScript
I built this library mostly as a learning exercise, but the code is also available as an npm module that can be consumed and used to build JavaScript applications using basically nothing but functions. I'm not sure why you would want to do that though!
Church encoding is a way of encoding data using only functions. For instance, we can use functions to represent, booleans, numerals and lists. Higher-order functions are all you need for Turing completeness.
Check out the docs.
npm i church
import {five, If, lt, map, mult, one, range, three, two} from 'church'
const twoFourSix = map(mult(two))(range(one)(three))
// => church encoded list of [two four six]
map(x => If(lt(x)(five))(five)(x))(twoFourSix)
// => church encoded list of [five five six]
The code is written in ES2015 and transpiled to ES5. You can consume the ES2015 source directly using Rollup.
Please do! I am no mathematician or computer scientist, so I am sure there are loads of improvements that could be made here.
- combinators-js - a library of combinators in JS I wrote
- http://raganwald.com/2015/02/13/functional-quantum-electrodynamics.html - totally mind-blowing article, this repo probably would not exist if I hadn't read it
- https://en.wikipedia.org/wiki/Church_encoding
- http://dictionary.sensagent.com/Church%20encoding/en-en/