How to best add logging/debugging code?

Simon Marlow simonmar at
Fri Nov 28 13:49:57 EST 2003

> Hmm.  This suggestion has the potential to confuse the casual user
> even more.  Consider
>     debug s x = trace (s++": "++show x++"\n") x
>     f x = debug ("entered f") (... g y ...)
>     g y = debug ("entered g") (...)
>     main =  ... f ...
> With the current definition of 'trace', although the formatting is
> ugly, the user (correctly) sees that the evaluation of f is entered
> before g.
>     entered f: entered g: val_g_y
>     val_f_x

The current implementation of Debug.Trace does indeed do this, but the
behaviour can be altered by changing the buffering mode of stderr.  Try

import System.IO
import Debug.Trace

main = do
  hSetBuffering stderr (BlockBuffering Nothing)
  trace ("a" ++ trace "b" "") (return ())

AFAIK, it's been this way for a long time.


More information about the Libraries mailing list