import qualified Data.Map as Map
from Data.Func import $
import Data.Maybe
+import Data.Void
import Data.Either
import Data.Functor
import Control.Applicative
(case mt of
Nothing = let t = IdType f in putIdent f t >>| pure t
Just t = putIdent f t >>| pure t) >>= \ft ->
- mapM_ (\a-> freshIdent >>= \fr-> putIdent a (IdType fr)) args >>|
- mapM_ semVarDecl vds >>|
+ matchFunctions args ft >>|
+ mapM semVarDecl vds >>= \newvds->
mapM_ (checkStmt $ resultType ft) stmts >>|
- restoreGamma gamma >>| pure fd
+ 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
+matchFunctions [x:xs] (t1 ->> t2) =
+ modify (\(st, r)->('Map'.put x t1 st, r)) >>| matchFunctions xs t2
semVarDecl :: VarDecl -> Env VarDecl
semVarDecl (VarDecl pos type ident ex) = unify type ex
saveGamma = get
restoreGamma :: Gamma -> Env Void
-restoreGamma g = put g
\ No newline at end of file
+restoreGamma g = put g