From 249bdba5121bca15012597a09e63a242781b001b Mon Sep 17 00:00:00 2001 From: pimjager Date: Tue, 12 Apr 2016 23:31:47 +0200 Subject: [PATCH] MonadTransformers work --- examples/varEx.spl | 17 +++++++++-------- sem.icl | 13 +++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/varEx.spl b/examples/varEx.spl index c400caf..f987631 100644 --- a/examples/varEx.spl +++ b/examples/varEx.spl @@ -1,10 +1,11 @@ +Int a = 1 + 1; +var b = True; +var c = 2 + 2; +var d = True; +var e = 4; +Int f = 4 + True; -Int t = 1 + 1; -var t = True; -var x = 2 + 2; - -var x = True; -var z = 4; -//Int y = 4 + True; - +facR(n) :: Int -> Int { + return 5; +} \ No newline at end of file diff --git a/sem.icl b/sem.icl index a973a02..fc8614b 100644 --- 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 -- 2.20.1