Skip to content

Instantly share code, notes, and snippets.

@vit0rr
Last active October 30, 2022 00:52
Show Gist options
  • Save vit0rr/5db424611f66cbfd17f86071ae3bc334 to your computer and use it in GitHub Desktop.
Save vit0rr/5db424611f66cbfd17f86071ae3bc334 to your computer and use it in GitHub Desktop.
Church encoding of True, False and Or
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