Hi, I am writing an interpreter of C-like, a statically typed language in Haskell. I want to do type checking before executing the code, but I have some problems with it. First of all, below are some type definitions from my abstract syntax:
newtype Ident = Ident String deriving (Eq,Ord,Show)
data Exp = {
data Type = TInt | TDouble | {
type TCM a = ErrorT String (Reader Env) a
TCM is designed to report errors and transfer media, for example:
typeof (EVar v) = do
env <- ask
case M.lookup v env of
Nothing -> throwError $ "undefined variable" ++ v ++ "\n"
Just t - > return t
Now I want to check the type of expressions, so I have a function that performs checks:
typeof Exp :: Exp -> TCM Type
It is defined for all cases, but one:
typeof (EFuncWithParams f l)
. , f ( , , , ) , , f , . , haskell , . :)
EDIT:
, , , , EFuncWithParams Ident [Exp] - (, , ), f (2 + 3, a, b [0]), TFunction [Exp]. - :
data Function_def =
Func Type_specifier Declarator Compound_stm
deriving (Eq,Ord,Show)
Declarator:
data Declarator = FuncDec Ident Parameter_declarations
- _
, , , - , , . , :
typeof_stm :: Stm -> TCM Type -- Function_def is a statement
, , , , (, typeof_stm), (, typeof). , , , , .