[Haskell-cafe] how do you debug programs?

Tamas K Papp tpapp at Princeton.EDU
Thu Sep 7 04:53:01 EDT 2006


On Wed, Sep 06, 2006 at 11:34:05AM +0200, Pepe Iborra wrote:
> Hi Tamas
> 
> There are several ways to debug a Haskell program.
> 
> The most advanced ones are based in offline analysis of traces, I
> think Hat [1] is the most up-to-date tool for this. There is a Windows
> port of Hat at [5].
> 
> Another approach is to simply use Debug.Trace. A more powerful
> alternative for this approach is Hood [2]. Even if it hasn't been
> updated in some time, Hood works perfectly with the current ghc
> distribution. Even more, Hugs has it already integrated [3]. You can
> simply import Observe and use observations directly in your program.

Dear Pepe,

Thank you for the information.  I finally ended up working with
Debug.Trace, and found the bug very quickly.  I also tried Hood, but
couldn't load it in ghci: import Observe can't find the library, but

% locate Observe
/usr/lib/ghc-6.4.2/hslibs-imports/util/Observe.hi
/usr/lib/ghc-6.4.2/hslibs-imports/util/Observe.p_hi
/usr/lib/hugs/libraries/Hugs/Observe.hs
/usr/lib/hugs/oldlib/Observe.hs

Does importing from hslibs-imports require something special?

Quite a bit of philosophical discussion erupted as a result of my
original question.  I understand the arguments of those who dislike
debuggers, but I don't think I could have done without some debugging.

It turns out that the problem was not in the algorithm, but in the
specification of the equation itself.  I was solving a continuous time
Hamilton-Jacobi-Bellman equation, and there was a point in the state
space where the supremum was infinity, giving stuff like 0/Inf and
their ilk.  I respecified the problem and now it works.

For those who think that it is always possible to break the problem up
into small pieces you can test individually (without a debugger): you
can't, at least not when solving functional equations.  The corner
cases (and nonconvergence, when using non-contraction methods, such as
PEA) are difficult to catch and reproduce.

Thanks for all the suggestions,

Tamas


More information about the Haskell-Cafe mailing list