This commit is contained in:
2026-05-07 09:58:43 -06:00
parent 91b3cf2870
commit 9add4ed242
3 changed files with 71 additions and 58 deletions
+18 -15
View File
@@ -20,19 +20,20 @@ type Name = Text
data Prim = PrimAdd | PrimSub | PrimMul | PrimDiv
deriving (Show, Generic)
data Val
= ValInt Int
| ValNil
| ValPrim Prim
| ValLambda (List Name) Exp
| ValVar Name
data Lit
= LitInt Int
| LitNil
| LitBool Bool
deriving (Show, Generic)
data Exp
= ExpLet (NonEmpty (Name, Exp)) Exp
| ExpApply Exp (List Exp)
| ExpBegin (List Exp)
| ExpVal Val
| ExpLit Lit
| ExpPrim Prim
| ExpLambda (List Name) Exp
| ExpVar Name
deriving (Show, Generic)
@@ -45,24 +46,26 @@ instance SexpIso Prim where
$ With (. sym "/")
$ End
instance SexpIso Val where
instance SexpIso Lit where
sexpIso = match
$ With (. sexpIso)
$ With (. sym "nil")
$ With (. sexpIso)
$ With lam
$ With (. symbol)
$ End
where
lam q = q . list
( el (sym "lambda")
>>> el (sexpIso @(List Name))
>>> el sexpIso )
instance SexpIso Exp where
sexpIso = match
$ With (. Gyehoek.Sexp.let_ symbol sexpIso sexpIso)
$ With (\app -> app . list (el sexpIso >>> rest sexpIso))
$ With (\bgn -> bgn . list (el (sym "begin") >>> rest sexpIso))
$ With (<<< sexpIso)
$ With (. sexpIso)
$ With (. sexpIso)
$ With (. lam)
$ With (. symbol)
$ End
where
lam = list
( el (sym "lambda")
>>> el (sexpIso @(List Name))
>>> el sexpIso )