Skip to content

Instantly share code, notes, and snippets.

@tamj0rd2
Created May 16, 2020 21:14
Show Gist options
  • Select an option

  • Save tamj0rd2/94cb97ea97d5cd70bae60602ba88c93f to your computer and use it in GitHub Desktop.

Select an option

Save tamj0rd2/94cb97ea97d5cd70bae60602ba88c93f to your computer and use it in GitHub Desktop.
// Church numeral encoding
const ZERO = f => x => x
const increment = n => f => x => n(f)(x)
// do not try to understand this. This way madness lies...
const decrement = n => f => x => n(g => h => h(g(f)))(u => x)(u => u)
// we're going to keep this simple for now, but trust me that booleans are also an interface...
const isZero = n => n(()=>{})(true) === (true)
exports.ZERO = ZERO
exports.increment = increment
exports.decrement = decrement
exports.isZero = isZero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment