On Mon, Sep 26, 2011 at 9:25 AM, Twan van Laarhoven <twanvl@gmail.com> wrote:
> Hello list,
>
>
> Currently the 'state' function is only defined for the State type (aka
> StateT Identity):
>
> state :: (s -> (a, s)) -> State s a
> state f = StateT (Identity . f)
>
> But this function makes sense for all MonadState instances. I therefore
> propose to either add it to the MonadState class:
>
> class MonadState s m | m -> s where
> ...
> state :: (s -> (a,s)) -> m a
> state f = do s <- get
> let (a,s') = f s
> set s'
> return a
>