aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Dybiec <pawel.to.malpa@gmail.com>2020-01-09 18:12:52 +0100
committerPaweł Dybiec <pawel.to.malpa@gmail.com>2020-01-09 18:12:52 +0100
commit0c4936c130cadb135faa54034ec2009cf189636e (patch)
treebcfa352b5cf7db5e655d52d709748c8cf9b1659e /src
parentAdd package.yaml (diff)
Fix variant type
Diffstat (limited to 'src')
-rw-r--r--src/Syntax.hs2
-rw-r--r--src/Typecheck.hs6
2 files changed, 6 insertions, 2 deletions
diff --git a/src/Syntax.hs b/src/Syntax.hs
index 1c888b5..c33f7b3 100644
--- a/src/Syntax.hs
+++ b/src/Syntax.hs
@@ -11,7 +11,7 @@ data Typ = TInt
data Expr = Var Idnt
| IntLit Int
| Record [(Idnt, Expr)]
- | Variant Typ [(Idnt, Expr)]
+ | Variant Typ Idnt Expr
| Add Expr Expr
| Mult Expr Expr
| Neg Expr
diff --git a/src/Typecheck.hs b/src/Typecheck.hs
index d8b8128..02b9871 100644
--- a/src/Typecheck.hs
+++ b/src/Typecheck.hs
@@ -19,7 +19,11 @@ inferExpr :: Expr -> Environment -> Maybe Typ
inferExpr (Var name) env = lookup name env
inferExpr (IntLit _) _ = Just TInt
inferExpr (Record _) _ = undefined
-inferExpr (Variant _ _) _ = undefined
+inferExpr (Variant t v e) env = do
+ ts <- assertVar t
+ tt <- lookup v ts
+ checkExpr e env tt
+ return t
inferExpr (Add e1 e2) env = do
checkExpr e1 env TInt
checkExpr e1 env TInt