
I'm developing a back end for GHC and I have the following problem: my program is throwing an "empty list exception" due to head [] and I need to compile GHC with -prof -auto-all in order to see the stack trace when running it with +RTS -xc -RTS. I changed the makefile but the option +RTS -xc -RTS was not recognized as an available RTS option
Does anyone have any idea about how I can do that ?
Hi,
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.
Whenever you read some code that includes an unguarded call to
head (where the non-emptyness of the list is not immediately obvious),
you are looking at a nasty trouble spot - get rid of it now!
At the very least, use something like Control.Exception.assert to guard
uses of partial functions like head, or define your own "safeHead":
safeHead msg [] = error msg
safeHead msg (h:_) = h
and replace unguarded uses of head with calls to safeHead "