<div>On Mon, Sep 26, 2011 at 10:41 AM, Antoine Latter <span dir="ltr"><<a href="mailto:aslatter@gmail.com">aslatter@gmail.com</a>></span> wrote:</div><div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Mon, Sep 26, 2011 at 9:25 AM, Twan van Laarhoven <<a href="mailto:twanvl@gmail.com">twanvl@gmail.com</a>> wrote:<br>
> Hello list,<br>
><br>
><br>
> Currently the 'state' function is only defined for the State type (aka<br>
> StateT Identity):<br>
><br>
> state :: (s -> (a, s)) -> State s a<br>
> state f = StateT (Identity . f)<br>
><br>
> But this function makes sense for all MonadState instances. I therefore<br>
> propose to either add it to the MonadState class:<br>
><br>
> class MonadState s m | m -> s where<br>
> ...<br>
> state :: (s -> (a,s)) -> m a<br>
> state f = do s <- get<br>
> let (a,s') = f s<br>
> set s'<br>
> return a<br>
><br></div></blockquote><div><br></div><div>I am 100% behind this change. </div><div><br></div><div>It has been on the short list of changes that I want to make to mtl.<div><br></div></div><div>The main reason that I like it aside from the fact that it witnesses the canonical monad homomorphism from State is that it yields more efficient definitions for functions like modify, and the often-needed but needlessly expensive operations where you bump a counter _and_ want the result for something like a fresh variable supply.</div>
<div><br></div><div>I would like to encourage further public discussion.</div></div></div></div>