e5c1d7c3878480ea9a489eec3893172a505705c6
[cc1516.git] / rwst.icl
1 implementation module rwst
2
3 from Data.Func import $
4 import Data.Functor
5 import Data.Monoid
6 import Control.Monad
7 import Control.Applicative
8
9
10 Start = "Test"
11
12 :: RWST r w s m a = RWST (r s -> m (a, s, w))
13
14 runRWST :: (RWST r w s m a) r s -> m (a, s, w)
15 runRWST (RWST f) r s = f r s
16
17 instance Functor (RWST r w s m) | Monad m & Monoid w where
18 fmap f m = liftM f m
19
20 instance Applicative (RWST r w s m) | Monad m & Monoid w where
21 pure a = RWST \_ s->pure (a, s, mempty)
22 (<*>) mf mx = ap mf mx
23
24 instance Monad (RWST r w s m) | Monad m & Monoid w where
25 bind m k = RWST \r s->runRWST m r s
26 >>= \(a, s`, w)->runRWST (k a) r s`
27 >>= \(b, s``,w`)->pure (b, s``, mappend w w`)