Skip to content

Instantly share code, notes, and snippets.

@deech
Last active August 29, 2015 13:55
Show Gist options
  • Save deech/8762022 to your computer and use it in GitHub Desktop.
Save deech/8762022 to your computer and use it in GitHub Desktop.
--- 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