[Haskell-beginners] Using Debug.Trace
Edward Z. Yang
ezyang at MIT.EDU
Sun Aug 8 14:20:38 EDT 2010
Excerpts from Patrick LeBoutillier's message of Sun Aug 08 13:14:41 -0400 2010:
> The getVersion and getDocument functions use the Data.Binary.Get monad
> to decode the byte string into various objects.
> I tried sprinkling "trace" calls a bit everywhere and I realize they
> don't always get called at the expected time. Most of them are only
> called when I reach the "putStrLn $ show stuff" statement. [snip]
>
> Is this happening because I'm using lazy IO to read the file?
> Is there a way to force the evaluation of these "trace" calls?
> Are there any other ways to debug this kind of stuff in Haskell?
To be more precise, this is happening because Haskell is processing
the file lazily. My feeling is forcing the evaluation of the trace
calls using seq or similar won't be too helpful, because your error
is earlier than that, in your definition of the Get monad. If you
trace in the monad before you exhaust the input stream, you should
get useful info; the function getRemainingLazyByteString may also
come in handy.
Cheers,
Edward
More information about the Beginners
mailing list