Proposal: Improved error message of "Error in array index"

Bulat Ziganshin bulatz at
Mon Nov 7 12:58:59 EST 2005

Hello Rene,

Sunday, November 06, 2005, 10:35:48 PM, you wrote:

RdV> I suggest that the code in GHC.Arr be changed from

RdV> error "Error in array index"

RdV> to

RdV> error "Error in array index" ++ show b ++ show i

one time i complained the close problem SPJ answered me:

| 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:bulatz at

More information about the Glasgow-haskell-users mailing list