diff options
-rw-r--r-- | src/Syntax.hs | 2 | ||||
-rw-r--r-- | src/Typecheck.hs | 6 |
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 |