diff options
author | Paweł Dybiec <pawel.to.malpa@gmail.com> | 2020-01-09 18:15:43 +0100 |
---|---|---|
committer | Paweł Dybiec <pawel.to.malpa@gmail.com> | 2020-01-09 18:15:43 +0100 |
commit | 9a2416d9395a97b1bd09ab191c00f7e44d850885 (patch) | |
tree | 26a2731082f7b54c1b2a13579d536f566d5e65b0 /src | |
parent | Fix infer for deref and arithmetic expressions (diff) |
Infer for record types
Diffstat (limited to 'src')
-rw-r--r-- | src/Typecheck.hs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Typecheck.hs b/src/Typecheck.hs index f6621a0..c86187d 100644 --- a/src/Typecheck.hs +++ b/src/Typecheck.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TupleSections #-} module Typecheck (inferExpr, checkExpr) @@ -15,10 +16,13 @@ assertVar _ = Nothing assertPtr (TPtr t) = Just t assertPtr _ = Nothing + inferExpr :: Expr -> Environment -> Maybe Typ inferExpr (Var name) env = lookup name env inferExpr (IntLit _) _ = Just TInt -inferExpr (Record _) _ = undefined +inferExpr (Record ts) env = do + tts <- sequence $ map (\(v,e) -> (v,) <$> inferExpr e env) ts + return $ TRecord tts inferExpr (Variant t v e) env = do ts <- assertVar t tt <- lookup v ts |