I ran some code through GHCI, and got this error:
*** Exception: Prelude.!!: index too large
After a while I went on to fix the bug (which was caused, as you might imagine, by an index that was too large), but I wish GHC would have told me at what line this large index was being evaluated.
Is there a way to either
You can use GHC's profiling facilities to get a kind of stack trace on errors, for example, suppose this is your source file:
xs :: [Int]
xs = [1..10]
foo :: Int -> IO ()
foo i = print $ xs !! i
main :: IO ()
main = mapM_ foo [1..10]
If you compile this with
ghc --make -prof -fprof-auto StackTrace.hs
then run it as
./StackTrace +RTS -xc
then you get
*** Exception (reporting due to +RTS -xc): (THUNK_1_0), stack trace:
GHC.List.CAF
--> evaluated by: Main.foo,
called from Main.main,
called from Main.CAF
StackTrace: Prelude.!!: index too large
which at least tells you the main
→ foo
chain.
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