update'
[cc1516.git] / sem.icl
diff --git a/sem.icl b/sem.icl
index 603d53a..727fc1e 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -3,6 +3,7 @@ implementation module sem
 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
@@ -49,10 +50,17 @@ semFunDecl fd=:(FunDecl p f args mt vds stmts) =
     (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
@@ -238,4 +246,4 @@ saveGamma :: Env Gamma
 saveGamma = get
 
 restoreGamma :: Gamma -> Env Void
-restoreGamma g = put g
\ No newline at end of file
+restoreGamma g = put g