I am looking for something to replace loch (and its preprocessor) since it doesn't compile with ghc 7.
Specifically, if error
is called then I would like to figure out, as conveniently as possible, where it was called from (line number and stack trace would be nice).
You can use the -xc
RTS option, as described on this page; you need to compile your program with profiling support, and the output is pretty ugly, but it works.
This should do it:
$ ghc --make -prof -auto-all myprog.hs
$ ./myprog +RTS -xc
Technically this only gives a cost centre stack, not a true stack trace. Improved stack trace support is coming in GHC 7.4.
If this is for use in code you're working on, and you can tolerate using Template Haskell, the placeholders
package is a cute and simple way to do something like this. It won't help you find the location of actual error
expressions, though, only uses of its own error
-like functions.
It's pretty trivial to get it to build with GHC-7. It's just the Control.Exception
change that came with 6.12, the simple fix is to change the Exception
type to SomeException
in Debug.Trace.Location
, line 70 and add an expression type signature in line 144. Restrict the base
dependency to >= 4.2 && < 4.6
in the .cabal file (bump the version) and you're good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With