From b5b044ceb4c178a656c0ddc27adec4a719b35893 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 24 Jul 2020 21:53:41 +0200 Subject: Support tuples --- ast/CC/Typed.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ast/CC/Typed.hs') diff --git a/ast/CC/Typed.hs b/ast/CC/Typed.hs index 535fd31..53caa29 100644 --- a/ast/CC/Typed.hs +++ b/ast/CC/Typed.hs @@ -3,6 +3,8 @@ module CC.Typed( module CC.Types ) where +import Data.List + import CC.Pretty import CC.Types @@ -15,12 +17,14 @@ data DefT = DefT Name ExprT data TypeT = TFunT TypeT TypeT | TIntT + | TTupT [TypeT] | TyVar Int deriving (Show, Read) data ExprT = LamT TypeT Occ ExprT | CallT TypeT ExprT ExprT | IntT Int + | TupT [ExprT] | VarT Occ deriving (Show, Read) @@ -31,12 +35,15 @@ exprType :: ExprT -> TypeT exprType (LamT typ _ _) = typ exprType (CallT typ _ _) = typ exprType (IntT _) = TIntT +exprType (TupT es) = TTupT (map exprType es) exprType (VarT (Occ _ typ)) = typ instance Pretty TypeT where prettyPrec _ TIntT = "Int" prettyPrec p (TFunT a b) = precParens p 2 (prettyPrec 3 a ++ " -> " ++ prettyPrec 2 b) + prettyPrec _ (TTupT ts) = + "(" ++ intercalate ", " (map pretty ts) ++ ")" prettyPrec _ (TyVar i) = 't' : show i instance Pretty ExprT where @@ -48,6 +55,7 @@ instance Pretty ExprT where precParens p 2 $ prettyPrec 3 e1 ++ " " ++ prettyPrec 3 e2 ++ " :: " ++ pretty ty prettyPrec _ (IntT i) = show i + prettyPrec _ (TupT es) = "(" ++ intercalate ", " (map pretty es) ++ ")" prettyPrec p (VarT (Occ n t)) = precParens p 2 $ show n ++ " :: " ++ pretty t -- cgit v1.2.3-54-g00ecf