Last active
August 29, 2015 13:55
-
-
Save deech/8762022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- StackTraced.hs | |
module StackTraced | |
(StackTraced.head) | |
where | |
import Debug.Trace | |
import Control.Exception | |
import System.IO.Unsafe | |
stackTrace ::SomeException -> IO a | |
stackTrace e = traceStack (show e) $ error "empty head" | |
head :: [a] -> a | |
head xs = unsafePerformIO $ (evaluate (Prelude.head xs)) `catch` stackTrace | |
--- CallStack.hs | |
import StackTraced | |
import Prelude hiding (head) | |
f = head $ drop 1 ["a"] | |
main = print f | |
---- | |
> ghc -prof -fprof-auto CallStack.hs | |
> ./Callback | |
Prelude.head: empty list | |
Stack trace: | |
StackTraced.stackTrace (StackTraced.hs:8:1-55) | |
StackTraced.head (StackTraced.hs:10:1-75) | |
Main.f (CallStack.hs:3:1-23) | |
GHC.List.CAF (<entire-module>) | |
CallStack: empty head | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment