[Haskell-cafe] Closure trace?

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed Jun 14 05:29:43 EDT 2006

Hello Michael,

Wednesday, June 14, 2006, 1:19:03 PM, you wrote:

> frequently we are seeing messages like "List.head: empty list" or
> "Maybe.fromJust: Nothing". It is clear what happened and where the

one time i complained the close problem SPJ answered me (see ghc-users
mail-list at 23 may 2005):

| also it will be cool to have ability to add such annotations to my own
| functions, smthg like:
| head (x:xs) = x
| head [] = superError "head []"
| which will print: "Error: head [] in Module.hs:155"

A difficulty is that the caller of 'head' might itself be called from
somewhere else:

        foo (xs, ys) = head xs

It's not much help to know that head failed when called from foo; you
want to know where foo is called from.  In short, you really want the
whole call stack.  But trimmed in the recursive case...

It's all very like cost-centre stacks, which is why GHC provides the -xc
option when you are profiling.  I think that give you what you want ---
but you have to compile your program profiled.

Another take on this is that you want an implicit parameter

        head :: (%loc :: Location) => [a] -> a

so that 'head' can report %loc when it fails.  Now you'd need to give
rules to say where %loc is bound.  It'd be a pretty magic kind of
implicit parameter.  Or should it be a stack of locations?

I'm not belittling the underlying problem, which is real.  But there do
seem to be many possible design choices without an obvious optimium.  If
someone can boil out a principled and simple solution, it'd be a good


Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list