type check preparation: add types to oracle

This commit is contained in:
ProgramSnail 2025-11-05 01:58:03 +03:00
parent b7963e87a6
commit edc6c373b0
8 changed files with 179 additions and 803 deletions

View file

@ -3,13 +3,6 @@ module TypeCheck where
import Expr
import Control.Monad
data Type = BoolT
| IntT
| ListT Type
| TreeT Type
| AnyT
deriving (Read, Show, Eq, Ord)
typeOf :: Value -> Type
typeOf (BoolV {}) = BoolT
typeOf (IntV {}) = IntT
@ -25,9 +18,6 @@ isList x | ListT {} <- typeOf x = True
isTree x | TreeT {} <- typeOf x = True
| otherwise = False
data TypeConf = TypeConf { typeConfInput :: [Type],
typeConfOutput :: Type }
checkType :: TypeConf -> Expr -> Maybe Type
checkType conf (left :&&: right) = do BoolT <- checkType conf left
BoolT <- checkType conf right
@ -70,7 +60,7 @@ checkType conf (left ::: right) = do t <- checkType conf left
ListT u <- checkType conf right
guard $ t == u
return $ ListT t
checkType conf EmptyListE = return $ ListT AnyT -- TODO
checkType conf EmptyListE = return $ ListT AnyT -- TODO FIXME: deal with AnyT
checkType conf (IsLeafE e) = do TreeT _ <- checkType conf e
return BoolT
checkType conf (TreeValE e) = do TreeT t <- checkType conf e