[Haskell-cafe] Re: how do you debug programs?

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Wed Sep 6 12:15:20 EDT 2006

Andrae Muys <andrae at netymon.com> wrote:

> It's a truism to say if your code doesn't work it's because you don't 
> understand it; ...

Indeed, but tracing the execution of the code, on the test example where
it fails, will often give insight into one's misunderstanding.  And often,
the person trying to fix some code is not even the person who wrote it.

Help with understanding a program is the job of tracing tools like Hat,
Hood, or Buddha.  (These are often called debuggers.)  And I believe
this is what the original poster was asking for - a tool to reveal what
his code _really_ does as opposed to what he _thinks_ it ought to do.
Is that so terrible?

Many people seem to think that banishing some misunderstanding of a
piece of code is as simple as staring at it until enlightenment hits.  I
can vouch for the fact that, when the code is complex (and necessarily
so, because the problem logic is complex), then tools are needed for
full comprehension of the logic.

For example, when presented with a bug report for the nhc98 compiler
(which I maintain but did not create), using Hat has been invaluable to
me in narrowing down which function is to blame in mere minutes.  Prior
to Hat, it sometimes took several days of reading sources by hand,
manually tracking possible stacks of function calls over large data
structures, before even finding the site of the error.

Large software systems are complex.  Tool support for understanding
their behaviour is not needed because we humans are stupid, but because
there is just too much information context to keep in one head-ful at a

> P.S. It is worth noting that I am here talking about the sort of  
> debugger raised in the original post. 
>                       - I'm talking about runtime debugging with  
> variable watches, breakpoints, and line-by-line stepping.

I don't believe that is necessarily what the original poster was asking
for.  And reduction-by-reduction stepping can be extremely useful for
beginners to understand how lazy evaluation works.


More information about the Haskell-Cafe mailing list