simple backtraces in ghci

Hal Daume III hdaume@ISI.EDU
Wed, 19 Jun 2002 10:51:51 -0700 (PDT)

Hi all,

Currently, I've been using the following hack to do backtraces:

namedEx :: String -> a -> a
namedEx fname x =
    unsafePerformIO $
    Exception.catch (x `seq` return x)
		 (\ex -> ioError (UserError (fname ++ " : " ++ show ex)))

At which point, if I have a function foo ... = ..., I change it to foo
... = namedEx "foo" $ ...

For instance:

foo l = namedEx "foo" $
	if head (bar l) == 1
	  then True
	  else foo (tail l)

bar l = namedEx "bar" $
	head l

This way I effectively get a backtrace as is offered in Java, SML/NJ,
Python and countless other languages.  I know that GHC is somewhat
intelligent about handing Exception.assert, where it will automatically
insert module names and line numbers for you, if you want.  I was
wondering if there was any chance of something like this getting hard
coded in.  I would want this turned off by default for compiled code, but
for code loaded in ghci, I find it very useful...

 - Hal

Hal Daume III

 "Computer science is no more about computers    |
  than astronomy is about telescopes." -Dijkstra |