Created
November 23, 2021 21:24
-
-
Save SimonMeskens/52560729c7c9225be037be0eb2818499 to your computer and use it in GitHub Desktop.
Lambda calculus in the TS type system
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 Test1 = λ<Not, [True]>; // False | |
type Test2 = λ<And, [True, False]>; // False | |
type Test3 = λ<And, [True, True]>; // True | |
// Boolean | |
interface True extends Func { expression: Var<this, 0>; } | |
interface False extends Func { expression: Var<this, 1>; } | |
interface Not extends Func { expression: λ<Var<this, 0>, [False, True]> } | |
interface And extends Func { expression: λ<Var<this, 0>, [Var<this, 1>, Var<this, 0>]> } | |
// Plumbing | |
type Func = { | |
variables: Func[]; | |
expression: unknown; | |
} | |
type Var<F extends Func, X extends number> = F["variables"][X]; | |
type λ<Exp extends Func, Vars extends unknown[]> = (Exp & { | |
variables: Vars; | |
})["expression"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment