How to best add logging/debugging code?

Manuel M T Chakravarty chak at cse.unsw.edu.au
Mon Nov 17 09:30:00 EST 2003


Ben Escoto <bescoto at stanford.edu> wrote,

> Hi all, does anyone have any tips on how to insert debugging or
> logging statements through a program?  Here are two possibilities:
[..]
> 2.  Use unsafePerformIO or similar.  But then your code is regularly
>     defeating the type system, which presumably isn't good.  Also the
>     ghc manual has special instructions for compiling code that uses
>     unsafePerformIO, intimating that it isn't used very often.

There is `Debug.Trace.trace' for this:

  http://haskell.org/ghc/docs/latest/html/base/Debug.Trace.html

However, if you want to log as opposed to debug, you may
want to have the output go to somewhere else but stdout.
Hence, it might be useful to have a variant of the `trace'
that takes an explicit file handle in the library.

Cheers,
Manuel


More information about the Haskell mailing list