on master help sign in
Add runState, evalState, execState and re-export Identity module
6d0c8f0Casper M. H. Holmgreen
libs/base/Control/Monad/State.idr+13−1
@@ -1,6 +1,6 @@
1module Control.Monad.State
1module Control.Monad.State
2
2
3−import Control.Monad.Identity
3+import public Control.Monad.Identity
4import Control.Monad.Trans
4import Control.Monad.Trans
5
5
6%access public
6%access public
@@ -55,3 +55,15 @@ gets f = do s <- get
55||| The State monad. See the MonadState class
55||| The State monad. See the MonadState class
56State : Type -> Type -> Type
56State : Type -> Type -> Type
57State s a = StateT s Identity a
57State s a = StateT s Identity a
58+
59+||| Unwrap a State monad computation.
60+runState : State s a -> s -> (a,s)
61+runState m = runIdentity . runStateT m
62+
63+||| Unwrap a State monad computation, but discard the final state.
64+evalState : State s a -> s -> a
65+evalState m = fst . runState m
66+
67+||| Unwrap a State monad computation, but discard the resulting value.
68+execState : State s a -> s -> s
69+execState m = snd . runState m