Created
December 7, 2023 17:52
-
-
Save smoofra/ba8c1d8861757e6be367257e2f7284e1 to your computer and use it in GitHub Desktop.
extendable trees
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 Grammer = { | |
"expression": unknown | |
} | |
type Expr<α extends Grammer> = α["expression"] | |
type Plus<α extends Grammer> = { | |
kind: "plus" | |
left: Expr<α> | |
right: Expr<α> | |
} | |
type Times<α extends Grammer> = { | |
kind: "times" | |
left: Expr<α> | |
right: Expr<α> | |
} | |
type Variable<α> = { | |
kind: "variable" | |
name: string | |
} | |
type AbelianGroupBaseGrammer<α extends Grammer> = { | |
"expression": Variable<α> | Plus<α> | |
} | |
type AbelianGroupGrammer = { | |
"expression": Expr<AbelianGroupBaseGrammer<AbelianGroupGrammer>> | |
} | |
type RingBaseGrammer<α extends Grammer> = { | |
"expression": Expr<AbelianGroupBaseGrammer<α>> | Times<α> | |
} | |
type RingGrammer = { | |
"expression": Expr<RingBaseGrammer<RingGrammer>> | |
} | |
const x : Expr<AbelianGroupGrammer> = {kind: "variable", name: "x"} | |
const y : Expr<AbelianGroupGrammer> = {kind: "variable", name: "y"} | |
const x_plus_y : Expr<AbelianGroupGrammer> = {kind:"plus", left: x, right: y} | |
const x_times_x_plus_y : Expr<RingGrammer> = {kind:"times", left: x, right: x_plus_y} | |
function group2ring(a : Expr<AbelianGroupGrammer>) : Expr<RingGrammer> { | |
return a | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment