13 lines
310 B
Plaintext
13 lines
310 B
Plaintext
data Expr = Lit Int | Add Expr Expr | Mul Expr Expr | Neg Expr
|
|
|
|
match simplify (e : Expr) : Expr =
|
|
| Add (Lit 0) x -> x
|
|
| Add x (Lit 0) -> x
|
|
| Mul (Lit 0) x -> Lit 0
|
|
| Mul x (Lit 0) -> Lit 0
|
|
| Mul (Lit 0) (Lit 1) -> Lit 0
|
|
| Mul (Lit 1) x -> x
|
|
| Mul x (Lit 1) -> x
|
|
| Neg (Neg x) -> x
|
|
| e -> e
|