我通过GHCI运行了一些代码,并收到了这个错误:
*** Exception: Prelude.!!: index too large
过了一段时间,我继续修复了这个错误(正如你可能想象的那样,由一个太大的索引引起的),但是我希望GHC会告诉我这个大索引的评估线是什么。
有没有办法
答案 0 :(得分:5)
You can use GHC's profiling facilities to get a kind of stack trace on errors,假设这是您的源文件:
xs :: [Int]
xs = [1..10]
foo :: Int -> IO ()
foo i = print $ xs !! i
main :: IO ()
main = mapM_ foo [1..10]
如果用
编译它ghc --make -prof -fprof-auto StackTrace.hs
然后将其作为
运行./StackTrace +RTS -xc
然后你得到
*** 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
至少告诉您main
→foo
链。