
Here are the +RTS -xc and mapException outputs together (when I remove the mapError annotations, only the first <..> is printed, so that is the part to focus on, the rest is confusion)
Actually, it looks as if the implementation of mapException modifies
the stack that +RTS -xc prints. Not entirely surprising, perhaps.
We can use that to illustrate the RULES for call site annotation suggestion,
by rewriting call sites of functions to be traced to prefix 'mapException id'
(see attached source).
That won't change the error message, because the RULES don't have the
source location we'd need there, but it will put a stack frame with lexical
stack info onto the stack.
On error, +RTS -xc prints the stack frames, corresponding to a dynamic
stack trace, each stack frame giving a lexical stack for an annotated call site.
1) no annotations, no +RTS -xc:
$ ghc -e main stacktracesXcHack.hs
-- fib 5
fib with non-positive number: 0
-- odd_ 5
odd_: no match
-- firstLetters2
Prelude.head: empty list
2) no annotations, +RTS -xc only:
$ ghc --make -prof -auto-all stacktracesXcHack.hs -DHACK
[1 of 1] Compiling Main ( stacktracesXcHack.hs, stacktracesXcHack.o )
Linking stacktracesXcHack.exe ...
$ ./stacktracesXcHack.exe +RTS -xc
-- fib 5