From 9a2416d9395a97b1bd09ab191c00f7e44d850885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dybiec?= Date: Thu, 9 Jan 2020 18:15:43 +0100 Subject: Infer for record types --- src/Typecheck.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') 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 -- cgit v1.2.3