module CC.Typed( module CC.Typed, module CC.Types ) where import CC.Pretty import CC.Types data ProgramT = ProgramT [DeclT] deriving (Show, Read) data DeclT = DefT DefT -- import? deriving (Show, Read) data DefT = FunctionT TypeT Name [Name] ExprT deriving (Show, Read) data TypeT = TFunT TypeT TypeT | TIntT | TyVar Int deriving (Show, Read) data ExprT = CallT TypeT ExprT ExprT | IntT Int | VarT Occ deriving (Show, Read) -- | Occurrence of a variable data Occ = Occ Name TypeT deriving (Show, Read) exprType :: ExprT -> TypeT exprType (CallT typ _ _) = typ exprType (IntT _) = TIntT 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 _ (TyVar i) = 't' : show i instance Pretty ExprT where prettyPrec p (LamT ty (Occ n t) e) = precParens p 2 $ "(\\(" ++ n ++ " :: " ++ pretty t ++ ") -> " ++ prettyPrec 2 e ++ ") :: " ++ pretty ty prettyPrec p (CallT ty e1 e2) = precParens p 2 $ prettyPrec 3 e1 ++ " " ++ prettyPrec 3 e2 ++ " :: " ++ pretty ty prettyPrec _ (IntT i) = show i prettyPrec p (VarT (Occ n t)) = precParens p 2 $ show n ++ " :: " ++ pretty t instance Pretty DefT where pretty (FunctionT n e) = n ++ " = " ++ pretty e instance Pretty DeclT where pretty (DefT def) = pretty def instance Pretty ProgramT where pretty (ProgramT decls) = concatMap ((++ "\n") . pretty) decls