MonadTransformers work
[cc1516.git] / sem.icl
diff --git a/sem.icl b/sem.icl
index a973a02..fc8614b 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -23,6 +23,10 @@ from parse import :: ParserOutput, :: Error
 :: Gamma :== 'Map'.Map String Type
 :: Env a :== StateT Gamma (Either SemError) a
 
+//we need to redefine this even though it is in Control.Monad.State
+instance MonadTrans (StateT Gamma) where
+    liftT m = StateT \s-> m >>= \a-> return (a, s)
+
 get = gets id
 
 instance toString SemError where
@@ -36,12 +40,9 @@ instance toString SemError where
         toString t1, ". Given: ", toString t2]
 
 putIdent :: String Type -> Env Void
-putIdent i t = undef
-/*putIdent i t = gets ('Map'.get i) >>= \mt -> case mt of
-    Nothing = pure <$> modify ('Map'.put i t)
-    Just t2 = unify t t2 >>= \r -> case r of
-        Left e  = pure $ Left e
-        Right t3 = pure <$> modify ('Map'.put i t3)*/
+putIdent i t = gets ('Map'.get i) >>= \mt -> case mt of
+    Nothing = modify ('Map'.put i t)
+    Just t2 = unify t t2 >>= \t3-> modify ('Map'.put i t3)
 
 sem :: AST -> SemOutput
 sem (AST vd fd) = case evalStateT m 'Map'.newMap of