git.iko.soy/typeable/haskell-stack-trace-plugin
on f42e35a help sign in
106 lines 2.4 kB history raw
1# haskell-stack-trace-plugin
3![](https://github.com/waddlaw/haskell-stack-trace-plugin/workflows/cabal/badge.svg)
4[![Hackage](https://img.shields.io/hackage/v/haskell-stack-trace-plugin.svg)](https://hackage.haskell.org/package/haskell-stack-trace-plugin)
6This plugin allow implicitly add `HasCallStack` class to every top-level function for all module. Hence, we can to get completely continuous call stack.
81. (implicitly) Import [GHC.Stack](https://hackage.haskell.org/package/base-4.12.0.0/docs/GHC-Stack.html) for all modules.
92. Add [HasCallStack](https://hackage.haskell.org/package/base-4.12.0.0/docs/GHC-Stack.html#t:HasCallStack) constraint for all top-level functions.
11Requirement: (8.6 <= on GHC)
13## Synopsis
15```haskell
16module Main where
18import Data.Maybe (fromJust)
20main :: IO ()
21main = print f1
23f1 :: Int
24f1 = f2
26f2 :: Int
27f2 = f3
29-- HsQualTy
30f3 :: HasCallStack => Int
31f3 = f4 0
33-- HsQualTy
34f4 :: Show a => a -> Int
35f4 _ = f5 0 0
37-- HsFunTy
38f5 :: Int -> Int -> Int
39f5 _ _ = head f6
41-- HsListTy
42f6 :: [Int]
43f6 = [fst f7]
45-- HsTupleTy
46f7 :: (Int, Int)
47f7 = (fromJust f8, fromJust f8)
49-- HsAppTy
50f8 :: Maybe Int
51f8 = Just fError
53-- HsTyVar
54fError :: Int
55fError = error "fError"
56```
58This example get error:
60```shell
61$ cabal new-build
62example/Main.hs:15:7: error:
63 Not in scope: type constructor or class ‘HasCallStack’
64 |
6515 | f3 :: HasCallStack => Int
66 | ^^^^^^^^^^^^
67```
69Yes, add `import GHC.Stack` to above example.
71Fix and rebuild!
73```shell
74$ cabal new-run
75example: fError
76CallStack (from HasCallStack):
77 error, called at example/Main.hs:41:10 in main:Main
78```
80Hmm, it is not useful. But, you will to be happy when enable this plugin.
82```cabal
83 ghc-options:
84 -fplugin=StackTrace.Plugin
85```
87```shell
88$ cabal new-run
89...
91example: fError
92CallStack (from HasCallStack):
93 error, called at example/Main.hs:40:10 in main:Main
94 fError, called at example/Main.hs:36:11 in main:Main
95 f8, called at example/Main.hs:32:16 in main:Main
96 f7, called at example/Main.hs:28:11 in main:Main
97 f6, called at example/Main.hs:24:15 in main:Main
98 f5, called at example/Main.hs:20:8 in main:Main
99 f4, called at example/Main.hs:16:6 in main:Main
100 f3, called at example/Main.hs:12:6 in main:Main
101 f2, called at example/Main.hs:9:6 in main:Main
102 f1, called at example/Main.hs:6:14 in main:Main
103 main, called at example/Main.hs:6:1 in main:Main
104```
106Great!!!