Created
May 16, 2020 21:14
-
-
Save tamj0rd2/94cb97ea97d5cd70bae60602ba88c93f to your computer and use it in GitHub Desktop.
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
| // 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