[Haskell-cafe] Printing call site for partial functions

Ketil Malde ketil at malde.org
Mon Apr 30 10:31:01 CEST 2012


Michael Snoyman <michael at snoyman.com> writes:

> I had a bug in a site of mine[1] for a few weeks, where it would just print:
>
>     Prelude.head: empty list
>
> It took a long time to track down the problem

+1: I've been arguing this for something like ten years :-)

One half-baked quasi-solution is to use:

#define head (\xs -> case xs of { (x:_) -> x ; _ -> error("head: empty list at"++__FILE__++show __LINE__)})

Downsides are that it depends on CPP, and, CPP being a C preprocessor,
it doesn't blend well with lines with single apostrophes on them (e.g.:
head x') 

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list