Proposal: add 'state' to the MonadState class
Bas van Dijk
v.dijk.bas at gmail.com
Sat Jan 21 22:13:35 CET 2012
On 26 September 2011 16:25, 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)
>
>
> Discussion period: 2 weeks (ends October 10th)
>
>
> Twan
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
+1
What happend to this proposal?
Edward, could you also list yourself as maintainer of mtl and list the
repository in the cabal file[1]?
Cheers,
Bas
[1] http://www.haskell.org/cabal/users-guide/#source-repositories
More information about the Libraries
mailing list