[Haskell-cafe] How to debug GHC

Donn Cave donn at drizzle.com
Tue Apr 26 14:34:15 EDT 2005


On Tue, 26 Apr 2005, Ketil Malde wrote:
> "Claus Reinke" <claus.reinke at talk21.com> writes:
>> no direct answer to your question, but a general comment on the
>> original problem (speaking from bad experience;-): things like
>> "head" have no place in a Haskell program of any non-trivial size,
>> because of their useless error messages.
> 
> I must say I liked John Meacham's description of his "magic
> underscore".  My solution to this problem is redefining the
> troublesome functions as cpp macros, e.g: 
> 
>   #define BUG(C_,M_) (error ("Program error - '"++C_++"' failed: "++M_++". Location: '"++__FILE__++"' line "++show __LINE__))
>   #define head (\xs -> case xs of { (x:_) -> x ; _ -> BUG("head","empty list")})
> 
> Ideally, I think something like this should be the default behavior
> for these functions. 

But something like this should happen for any function, shouldn't it?
I mean, ideally when we write a large program, we try to write many
functions that each support some general operation and are called many
times throughout the program at various levels, and maybe have some
potential to fail.  The ideal situation is when I can tell, from the
top level error handler output emailed to me by the person who ran into
the problem, who called who all the way from "main" to "head", because
the key function is going to be one somewhere in the middle.

Anything less general than this seems less than ideal to me.  If it's
obvious that it isn't good enough for head to announce that the error
came from "head", and instead we need to also identify head's caller,
then it should be obvious that this requirement is recursive.

	Donn Cave, donn at drizzle.com



More information about the Haskell-Cafe mailing list