started with new typechecker
[cc1516.git] / RWST.icl
index 4b38482..9caa0e6 100644 (file)
--- a/RWST.icl
+++ b/RWST.icl
@@ -1,5 +1,6 @@
 implementation module RWST
 
+from StdFunc import o
 import StdTuple
 
 from Data.Func import $
@@ -10,6 +11,26 @@ import Data.Monoid
 import Control.Monad
 import Control.Applicative
 
+// The RWS monad 
+:: RWS r w s a :== RWST r w s Identity a
+
+rws :: (r -> s -> (a, s, w)) -> RWS r w s a
+rws f = RWST \r s->Identity $ f r s
+
+runRWS :: (RWS r w s a) r s -> (a, s, w)
+runRWS m r s = runIdentity $ runRWST m r s
+
+evalRWS :: (RWS r w s a) r s -> (a, w)
+evalRWS m r s = let (a, _, w) = runRWS m r s in (a, w)
+
+execRWS :: (RWS r w s a) r s -> (s, w)
+execRWS m r s = let (_, s`, w) = runRWS m r s in (s`, w)
+
+mapRWS :: ((a, s, w) -> (b, s, w`)) (RWS r w s a) -> RWS r w` s b
+mapRWS f m = mapRWST (Identity o f o runIdentity) m
+
+withRWS :: (r` s -> (r, s)) (RWS r w s a) -> RWS r` w s a
+withRWS f m = withRWST f m
 
 // The RWST monad transformer
 :: RWST r w s m a = RWST (r s -> m (a, s, w))