
25 Sep
2008
25 Sep
'08
2:34 p.m.
On Thu, 25 Sep 2008, Anthony LODI wrote:
Hello haskell-cafe,
In my application I have a complex state threaded through long computation chains, and I need a way to log all state changes (so that the evolving state can be animated/replayed somewhere else). Initially I tried combining State and Writer monads but this allows for the possibility to change the state, and forget to write a log entry, etc.
Instead of rewriting from scratch, you can also define newtype StateWriter l s a = StateWriter (StateT s (Writer l) a) and then the monad instance is just about wrapping and unwrapping. Or you use {-# LANGUAGE GeneralizedNewtypeDeriving #-} and 'deriving Monad'.