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

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Wed Sep 6 11:31:49 EDT 2006

"Neil Mitchell" <ndmitchell at gmail.com> writes:

> Hi
> > > Yes, and if the compiler is this clever, it should also be free to
> > > replace them back at debug time.
> >
> > And where does that get us? You snipped the salient bit
> > where I said that you'd be debugging a different programme.
> In Visual C there are two compilation modes. In debug mode, if you
> create a variable "i" it WILL be there in the compiled version. It
> won't be merged with another variable. It won't be constant folded. It
> won't have its value globablly computed and stored. It won't be placed
> only in the register. In release mode all these things can (and do)
> happen. I'm not saying Haskell compilers aren't free to optimize, but
> maybe there is a need for one that is this "debug mode" style.

I think this chiefly indicates that you think of variables
as things, which in Haskell they are not.

> > At no point have I ever
> > used a debugger on a Haskell programme.
> Because you couldn't find a working debugger? ;) If one had been
> there, just a click away, would you never have been tempted?

Not in the least. The highest level language I've ever
wanted to use a debugger on was C, and that was for
debugging a pointer-reversing garbage collector, which ties
in with what Andrae says.

> Let take for example a bug I spent tracking down in Haskell this
> weekend. The bug can be summarized as "Program error: pattern match
> failure: head []". And indeed, thats all you get. A quick grep reveals
> there are about 60 calls to head in the program. In this instance I
> have the choice between 1) crying, 2) a debugger, 3) a lot of hard
> work. [Of course, knowing this situation arises, I had already
> prepared my getout plan, so it wasn't a massive problem]

H'm.  I've never been completely convinced that head should
be in the language at all.  If you use it, you really have
to think, every time you type in the letters h-e-a-d, “Am I
/really/ /really/ sure the argument will never be []?”
Otherwise you should be using a case expression or (more
often, I think) a subsidiary function with a pattern match.

Most of the occurrences of “head” in my code seem to be
applied to infinite lists, or commented out, or rebindings
of head to something else, sloppy bits of nonce programming
or references in comments to the top of my own noddle.

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2006-07-14)

More information about the Haskell-Cafe mailing list