[Haskell-cafe] Debugging Haskell code

Justin Bailey jgbailey at gmail.com
Tue Sep 29 15:50:08 EDT 2009


On Sun, Sep 27, 2009 at 12:50 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> The problem is that I have *no idea* how to begin debugging this. In
> C, Python, or any other imperative language, I'd put traces in, etc.
> But in Haskell, I don't even know where to start.
>

One of the standard modules is  Debug.Trace module, which does allow
you to print information to the console. It just may come in an odd
order and of course, it can change your program if you force
evaluation. Under the covers it is really "unsafePerformIO $ putStrLn
msg", i.e., it just prints to the console. I've found that forcing a
flush on the output stream can be useful too, so I've defined my own
trace before too.

There is also the GHC debugger, which is best described in the user
manual - read the section there to learn more.

If you hadn't already received help on the list, either of these could
be used to narrow down where the crash is occurring.

Justin


More information about the Haskell-Cafe mailing list