Last active
April 1, 2024 23:48
-
-
Save anabastos/a79a860f39bd4d884e3dd036f1445259 to your computer and use it in GitHub Desktop.
meus churchezinhos
This file contains 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
/* | |
ChUrChEsZiNhUs | |
baseado na palestra : https://www.youtube.com/watch?v=VpzhH9CXOy0 | |
*/ | |
const ID = x => x | |
const TRUE = x => y => x | |
TRUE("0")("1") // 0 | |
const FALSE = x => y => y | |
FALSE("0")("1") // 1 | |
const IF_THEN_ELSE = p => x => y => p(x)(y) | |
const toBool = b => IF_THEN_ELSE(b)(true)(false) | |
const AND = x => y => x(y)(FALSE) | |
const OR = x => y => x(TRUE)(y) | |
const NOT = x => x(FALSE)(TRUE) | |
toBool(AND(TRUE)(TRUE)), // true | |
toBool(AND(FALSE)(TRUE)), // false | |
toBool(AND(TRUE)(FALSE)), // false | |
toBool(AND(FALSE)(FALSE)) // false | |
toBool(OR(TRUE)(TRUE)), // true | |
toBool(OR(FALSE)(TRUE)), // true | |
toBool(OR(TRUE)(FALSE)), // true | |
toBool(OR(FALSE)(FALSE)) // false | |
toBool(NOT(TRUE)), // false | |
toBool(NOT(FALSE)) // true | |
const ZERO = f => x => x | |
const ONE = f => x => f(x) | |
const TWO = f => x => f(f(x)) | |
const THREE = f => x => f(f(f(x))) | |
const FOUR = f => x => f(f(f(f(x)))) | |
// recursao | |
const Y = f => (x => x(x))(y => f(x => y(y)(x))); | |
const SUCC = n => f => x => f(n(f)(x)) | |
const PRED = n => n(p => z => z(SUCC(p(TRUE)))(p(TRUE)))(z => z(ZERO)(ZERO))(FALSE) | |
const SUCC_PAIR = p => PAIR(SECOND(p))(SUCC(SECOND(p))) | |
const PRED = n => FIRST(n(SUCC_PAIR)(PAIR(ZERO)(ZERO))) | |
const FOUR2 = SUCC(THREE) | |
const ADD = n => m => m(SUCC)(n) | |
const SUB = n => m => m(PRED)(n) | |
const MULT = n => m => m(ADD(n))(ZERO) | |
const EXP = n => m => m(n) | |
const FIVE = ADD(TWO)(THREE) | |
const IZ = n => (x => FALSE)(TRUE) | |
const LEQ = m => n => IZ(SUB(m)(n)) | |
// const FIB = Y(r => n => IF(LEQ(n)(ONE))) | |
const toInt = n => n(x => x + 1)(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/terremoth/js-church-encoding