Proposal: add 'state' to the MonadState class
Antoine Latter
aslatter at gmail.com
Mon Sep 26 16:41:33 CEST 2011
On Mon, Sep 26, 2011 at 9:25 AM, Twan van Laarhoven <twanvl at 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
>
> or as a stand alone function like modify. I personally prefer to add it to
> the class, since that allows for a more efficient implementation. In
> particular:
>
> instance Monad m => MonadState s (StateT s m) where
> ....
> state = StateT (return . f)
>
>
I think that "mtl" has a real maintainer now - unless something
changed from the thread back in June I think Edward K. is doing the
duty, so I don't know that the libraries process strictly applies.
But that doesn't mean we can't have a discussion in public!
Would we make the corresponding change to the "monads-tf" package?
I think it is worth keeping their public API in sync to the extent
practical, but I don't know if the maintainers of the two packages
have a policy on that.
Antoine
More information about the Libraries
mailing list