on master help sign in
Add runState, evalState, execState and re-export Identity module

Idris can't resolve MonadState typeclasses unless it can see Identity. I chose to re-export it, otherwise users of the State monad will have to explicitly import both. import Control.Monad.Identity import Control.Monad.State

commit6d0c8f050170d341e63f2e2c0a4462dc099d3984 authorCasper M. H. Holmgreen <cholmgreen@gmail.com> dateMon 20 Apr 2015, 12:26 (12 years ago) parentc2580dc
1 file changed+13−1
libs/base/Control/Monad/State.idr+13−1
libs/base/Control/Monad/State.idr+13−1
@@ -1,6 +1,6 @@
11module Control.Monad.State
22
3−import Control.Monad.Identity
3+import public Control.Monad.Identity
44import Control.Monad.Trans
55
66%access public
@@ -55,3 +55,15 @@ gets f = do s <- get
5555||| The State monad. See the MonadState class
5656State : Type -> Type -> Type
5757State 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