State

ghc-7.6.3: The GHC API

Safe Haskell | Safe-Inferred

State

Synopsis

- newtype State s a = State {
  - runState' :: s -> (#a, s#)
  }
- get :: State s s
- gets :: (s -> a) -> State s a
- put :: s -> State s ()
- modify :: (s -> s) -> State s ()
- evalState :: State s a -> s -> a
- execState :: State s a -> s -> s
- runState :: State s a -> s -> (a, s)
- mapAccumLM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])

# Documentation

newtype State s a

Constructors

State |
Fields runState' :: s -> (#a, s#)

Instances

Monad (State s) |
Functor (State s) |
Applicative (State s) |

get :: State s s

gets :: (s -> a) -> State s a

put :: s -> State s ()

modify :: (s -> s) -> State s ()

evalState :: State s a -> s -> a

execState :: State s a -> s -> s

runState :: State s a -> s -> (a, s)

mapAccumLM

Arguments

:: Monad m |
=> (acc -> x -> m (acc, y)) | combining funcction
-> acc | initial state
-> [x] | inputs
-> m (acc, [y]) | final state, outputs

Monadic version of mapAccumL