[Haskell-cafe] Re: StateT and modify
nicolas.frisby at gmail.com
Wed Nov 8 12:11:09 EST 2006
Regardless of what monad is transformed by StateT, I think the OP's
modify below is straight from Gill's source at
modify :: (MonadState s m) => (s -> s) -> m ()
modify f = do
s <- get
put (f s)
we could add
modifyM :: (MonadState s m) => (s -> m s) -> m ()
modifyM f = do
s <- get
s' <- f s
which I think you could use...
modifyM is just a bit more flexible than Cale's liftModify, I think.
On 11/8/06, Max Vasin <max.vasin at gmail.com> wrote:
> >>>>> "Peter" == Peter Steiner <pnsteiner at gmail.com> writes:
> Peter> On 11/8/06, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> >> Hello Peter,
> >> Wednesday, November 8, 2006, 1:48:24 PM, you wrote:
> >> > i would like to be able to debug what's happening inside the
> >> modifier > function. that's why i want to be able to use a
> >> modifier that's in the > IO monad
> >> for debugging there is 'trace' function which don't needs IO
> >> monad
> Peter> thanks. i am aware of trace, but the potentially messed up
> Peter> execution order makes it very hard for me to get useful
> Peter> information out of the resulting trace. besides, IO will
> Peter> scale to more elaborate logging mechanisms later on...
> If all you want from IO is logging why not just use MonadWriter?
> Max Vasin.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe