semFunDecl :: FunDecl -> Env FunDecl
semFunDecl fd=:(FunDecl p f args mt vds stmts) = (case mt of
- Nothing = let t = IdType f in putIdent f t >>| pure t//typeFun f args
+ Nothing = let t = IdType f in putIdent f t >>| pure t
Just t = putIdent f t >>| pure t) >>= \ft ->
mapM_ semVarDecl vds >>|
mapM_ (checkStmt $ resultType ft) stmts >>| pure fd
- //case mt of
-// Nothing = let t = IdType f in putIdent f t >>| pure fd
-// Just t = putIdent f t >>| pure fd
semVarDecl :: VarDecl -> Env VarDecl
semVarDecl (VarDecl pos type ident ex) = unify type ex
checkStmt VoidType r=:(ReturnStmt Nothing) = pure r
checkStmt t r=:(ReturnStmt (Just e)) = unify t e >>| pure r
-all :: [Bool] -> Bool
-all as = foldr (&&) True as
-
typeExpr :: Expr -> Env Type
typeExpr (IntExpr _ _) = pure IntType
typeExpr (CharExpr _ _) = pure CharType
buildFunctionType frsh [e:es] = (->>) <$> typeExpr e <*> buildFunctionType frsh es
unifyApp :: Type [Expr] -> Env Type
-unifyApp t [] = pure t //whoop whoop, functions can return functions
+unifyApp t [] = pure t
unifyApp (tf1 ->> tf2) [t1:ts] = unify tf1 t1 >>| unifyApp tf2 ts
unifyApp t1 t2 = liftT $ Left $ UnifyError zero t1 (IdType "[expressions, FIXME]")