- mapM_ (checkStmt $ resultType ft) stmts >>|
- restoreGamma gamma >>|
- pure (FunDecl p f args mt newvds stmts)
-
-matchFunctions :: [String] Type -> Env Void
-matchFunctions [] (_ ->> _) = liftT $ Left $ Error "Niet genoeg argumentenerror"
-matchFunctions [] t = pure Void
+ mapM (checkStmt tres) stmts >>= \newstmts->
+ pure IntType >>= \returntype->
+ case mt of
+ Nothing = reconstructType args returntype
+ >>= \ftype->restoreGamma gamma
+ >>| putIdent f ftype >>| pure (
+ FunDecl p f args (Just ftype) newvds newstmts)
+ Just t = restoreGamma gamma
+ >>| pure (FunDecl p f args mt newvds newstmts)
+
+reconstructType :: [String] Type -> Env Type
+reconstructType [] t = pure t
+reconstructType [x:xs] t = gets (\(st, r)->'Map'.get x st)
+ >>= \mtype->case mtype of
+ Nothing = liftT $ Left $ Error "Not used ????"
+ Just type = reconstructType xs t >>= \resttype->pure (type ->> resttype)
+
+genType :: [String] -> Env Type
+genType [] = freshIdent >>= \fi->pure $ IdType fi
+genType [x:xs] = liftM2 (->>) (freshIdent >>= \fi->pure $ IdType fi)
+ (genType xs)
+
+matchFunctions :: [String] Type -> Env Type
+matchFunctions [] (_ ->> _) = liftT $ Left $ Error "Not enough arguments"
+matchFunctions _ (VoidType ->> _) = liftT $ Left $ Error "Cannot have a void type in the middle of the function definition"