How to best add logging/debugging code?

Ben Escoto bescoto at stanford.edu
Sun Nov 16 22:32:41 EST 2003


On 16 Nov 2003 22:43:55 +0100 Peter Simons <simons at cryp.to> wrote:
> This is definitely the way to go. The 'MonadWriter' class
> provides a very general interface, which often proves to be
> much more useful than just for logging. Especially, when you
> use it to return data types with useful information --
> rather than just strings. And 'mapWriter' gives you much
> flexibility, when it comes to creating glue code to convert
> different types of log events.
> 
> You can use the transforming variant to encapsulate other
> monads, like IO a. Then, running code that is unaware of
> logging requires a call to 'lift', and that's it.

Thanks for the pointer.  I had seen Control.Monad.Writer in the ghc
docs but previously didn't know what is was good for.  I will try to
learn how to use the various monad transformers and see how easy they
are elegant to use in practice.

For debugging (as opposed to logging) Debug.Trace looks good, thanks
to the other poster(s) for mentioning that.

Maybe eventually I will see a need for mapWriter.  As a passing
thought, I wonder how many programmers can read the mapWriterT
documentation:

mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b

and start pounding the code out?  Anyway, once I get this all sorted
out, I figure my program will have really nice logging, better than
fprintf(stderr, ...) even.


-- 
Ben Escoto
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://haskell.org/pipermail/haskell/attachments/20031116/f8e7ec09/attachment.bin


More information about the Haskell mailing list