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 #-}
1
2
-----------------------------------------------------------------------------
2
3
-- |
3
4
-- Module : Control.Monad.Indexed.State
@@ -90,6 +91,18 @@ instance IxMonadFix IxState where
90
91
91
92
newtype IxStateT m i j a = IxStateT { runIxStateT :: i -> m (a , j ) }
92
93
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
+
93
106
instance Monad m => Functor (IxStateT m i j ) where
94
107
fmap = imap
95
108
You can’t perform that action at this time.
0 commit comments