git.iko.soy/typeable/haskell-stack-trace-plugin
on 70854be help sign in
105 lines 2.3 kB history raw
1# haskell-stack-trace-plugin
3[![Hackage](https://img.shields.io/hackage/v/haskell-stack-trace-plugin.svg)](https://hackage.haskell.org/package/haskell-stack-trace-plugin)
5This plugin allow implicitly add `HasCallStack` class to every top-level function for all module. Hence, we can to get completely continuous call stack.
71. (implicitly) Import [GHC.Stack](https://www.stackage.org/haddock/lts-12.21/base-4.11.1.0/GHC-Stack.html) for all modules.
82. Add [HasCallStack](https://www.stackage.org/haddock/lts-12.21/base-4.11.1.0/GHC-Stack.html#t:HasCallStack) constraint for all top-level functions.
10Requirement: (8.6 <= on GHC)
12## Synopsis
14```haskell
15module Main where
17import Data.Maybe (fromJust)
19main :: IO ()
20main = print f1
22f1 :: Int
23f1 = f2
25f2 :: Int
26f2 = f3
28-- HsQualTy
29f3 :: HasCallStack => Int
30f3 = f4 0
32-- HsQualTy
33f4 :: Show a => a -> Int
34f4 _ = f5 0 0
36-- HsFunTy
37f5 :: Int -> Int -> Int
38f5 _ _ = head f6
40-- HsListTy
41f6 :: [Int]
42f6 = [fst f7]
44-- HsTupleTy
45f7 :: (Int, Int)
46f7 = (fromJust f8, fromJust f8)
48-- HsAppTy
49f8 :: Maybe Int
50f8 = Just fError
52-- HsTyVar
53fError :: Int
54fError = error "fError"
55```
57This example get error:
59```shell
60$ cabal new-build
61example/Main.hs:15:7: error:
62 Not in scope: type constructor or class ‘HasCallStack’
63 |
6415 | f3 :: HasCallStack => Int
65 | ^^^^^^^^^^^^
66```
68Yes, add `import GHC.Stack` to above example.
70Fix and rebuild!
72```shell
73$ cabal new-run
74example: fError
75CallStack (from HasCallStack):
76 error, called at example/Main.hs:41:10 in main:Main
77```
79Hmm, it is not useful. But, you will to be happy when enable this plugin.
81```cabal
82 ghc-options:
83 -fplugin=StackTrace.Plugin
84```
86```shell
87$ cabal new-run
88...
90example: fError
91CallStack (from HasCallStack):
92 error, called at example/Main.hs:40:10 in main:Main
93 fError, called at example/Main.hs:36:11 in main:Main
94 f8, called at example/Main.hs:32:16 in main:Main
95 f7, called at example/Main.hs:28:11 in main:Main
96 f6, called at example/Main.hs:24:15 in main:Main
97 f5, called at example/Main.hs:20:8 in main:Main
98 f4, called at example/Main.hs:16:6 in main:Main
99 f3, called at example/Main.hs:12:6 in main:Main
100 f2, called at example/Main.hs:9:6 in main:Main
101 f1, called at example/Main.hs:6:14 in main:Main
102 main, called at example/Main.hs:6:1 in main:Main
103```
105Great!!!