From 307919760c58e037ec3260fcd0c3c7f7227fd7aa Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 26 Feb 2024 22:59:54 +0100 Subject: WIP typecheck and other stuff --- src/HSVIS/AST.hs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/HSVIS/AST.hs') diff --git a/src/HSVIS/AST.hs b/src/HSVIS/AST.hs index 5a90205..f606d22 100644 --- a/src/HSVIS/AST.hs +++ b/src/HSVIS/AST.hs @@ -1,3 +1,7 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE StandaloneDeriving #-} module HSVIS.AST where import Data.List.NonEmpty (NonEmpty) @@ -17,18 +21,27 @@ data DataDef = DataDef Name [Name] [(Name, [Type])] data FunDef t = FunDef Name (Maybe Type) (NonEmpty (FunEq t)) deriving (Show) -data FunEq t = FunEq Name [Pattern t] (RHS t) +data FunEq t = FunEq t Name [Pattern t] (RHS t) deriving (Show) -data Type - = TApp Type [Type] - | TTup [Type] - | TList Type - | TFun Type Type - | TCon Name - | TVar Name +data TypeStage = TSTC | TSNormal deriving (Show) +data GType (stage :: TypeStage) where + TApp :: GType s -> [GType s] -> GType s + TTup :: [GType s] -> GType s + TList :: GType s -> GType s + TFun :: GType s -> GType s -> GType s + TCon :: Name -> GType s + TVar :: Name -> GType s + + -- Type constructor used only while type checking + TUniVar :: Int -> GType 'TSTC +deriving instance Show (GType stage) + +type TCType = GType 'TSTC +type Type = GType 'TSNormal + data Pattern t = PWildcard t | PVar t Name @@ -55,6 +68,7 @@ data Expr t | EIf t (Expr t) (Expr t) (Expr t) | ECase t (Expr t) [(Pattern t, RHS t)] | ELet t [FunDef t] (Expr t) + | EParseError deriving (Show) data Literal = LInt Integer | LFloat Rational | LChar Char | LString String -- cgit v1.2.3-70-g09d2