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 | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
What you're asking for is almost exactly the same as the -auto-all profiling option. The only difference is that you want to use your own function 'namedEx' instead of _scc_. It seems like it would be a fairly easy thing to generalise the -auto-all option: ghc --auto-all="namedEx" --extra-implicit-import="HalsBacktraceModule" -- Alastair
participants (2)
-
Alastair Reid -
Hal Daume III