Last active
October 30, 2022 00:52
-
-
Save vit0rr/5db424611f66cbfd17f86071ae3bc334 to your computer and use it in GitHub Desktop.
Church encoding of True, False and Or
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
type TRUE = <A>(a: A) => <B>(b: B) => A; | |
type FALSE = <A>(a: A) => <B>(b: B) => B; | |
type OR = <A extends TRUE | FALSE>(a: A) => <B extends TRUE | FALSE>(b: B) => TRUE | FALSE; | |
// (λx.λy.x) | |
const TRUE: TRUE = a => b => a; | |
console.log(TRUE(1)(0)); | |
// (λx.λy.y) | |
const FALSE: FALSE = a => b => b; | |
console.log(FALSE(1)(0)); | |
// (λx.λy.x TRUE y) | |
const OR = a => b => a(TRUE)(b); | |
console.log(OR(TRUE)(FALSE)(1)(0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment