2 -- The above warning supression flag is a temporary kludge.
3 -- While working on this module you are encouraged to remove it and fix
4 -- any warnings in the module. See
5 -- http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
12 { runState' :: s -> (# a, s #) }
14 instance Monad (State s) where
15 return x = State $ \s -> (# x, s #)
16 m >>= n = State $ \s ->
18 (# r, s' #) -> runState' (n r) s'
21 get = State $ \s -> (# s, s #)
23 gets :: (s -> a) -> State s a
24 gets f = State $ \s -> (# f s, s #)
26 put :: s -> State s ()
27 put s' = State $ \s -> (# (), s' #)
29 modify :: (s -> s) -> State s ()
30 modify f = State $ \s -> (# (), f s #)
33 evalState :: State s a -> s -> a
35 = case runState' s i of
39 execState :: State s a -> s -> s
41 = case runState' s i of
45 runState :: State s a -> s -> (a, s)
47 = case runState' s i of
48 (# a, s' #) -> (a, s')
53 => (acc -> x -> m (acc, y)) -- ^ combining funcction
54 -> acc -- ^ initial state
56 -> m (acc, [y]) -- ^ final state, outputs
58 mapAccumLM _ s [] = return (s, [])
62 (s2, xs') <- mapAccumLM f s1 xs