File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1+ {-# LANGUAGE RecordWildCards #-}
12-----------------------------------------------------------------------------
23-- |
34-- Module : Control.Monad.Indexed.State
@@ -90,6 +91,18 @@ instance IxMonadFix IxState where
9091
9192newtype IxStateT m i j a = IxStateT { runIxStateT :: i -> m (a , j ) }
9293
94+ -- | Lift a computation from the inner monad.
95+ lift :: Monad m => m a -> IxStateT m i i a
96+ lift ma = IxStateT $ (\ i -> ma >>= \ a -> return (a, i))
97+
98+ -- | Evaluate a computation in the monad from some initial state. Returns the resulting value.
99+ evalIxStateT :: Monad m => IxStateT m i j a -> i -> m a
100+ evalIxStateT IxStateT {.. } i = runIxStateT i >>= return . fst
101+
102+ -- | Evaluate a computation in the monad from some initial state. Returns the final state.
103+ execIxStateT :: Monad m => IxStateT m i j a -> i -> m j
104+ execIxStateT IxStateT {.. } i = runIxStateT i >>= return . snd
105+
93106instance Monad m => Functor (IxStateT m i j ) where
94107 fmap = imap
95108
You can’t perform that action at this time.
0 commit comments