git.iko.soy/typeable/haskell-stack-trace-plugin
on master help sign in
114 lines 2.6 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/docs/GHC-Stack.html) for all modules.
92. Add [HasCallStack](https://hackage.haskell.org/package/base/docs/GHC-Stack.html#t:HasCallStack) constraint for all top-level functions.
103. Other supported syntaxes
11 - [x] `where` clause
13Requirement: (8.6 <= on GHC)
15## Synopsis
17```haskell
18module Main where
20import Data.Maybe (fromJust)
22main :: IO ()
23main = print f1
25f1 :: Int
26f1 = f2
28f2 :: Int
29f2 = f3
31-- HsQualTy
32f3 :: HasCallStack => Int
33f3 = f4 0
35-- HsQualTy
36f4 :: Show a => a -> Int
37f4 n = f5 (show n) 0
39-- HsFunTy
40f5 :: String -> Int -> Int
41f5 _ _ = head f6
43-- HsListTy
44f6 :: [Int]
45f6 = [fst f7]
47-- HsTupleTy
48f7 :: (Int, Int)
49f7 = (fromJust f8, fromJust f8)
51-- HsAppTy
52f8 :: Maybe Int
53f8 = Just f9
55f9 :: Int
56f9 = f10
57 where
58 f10 :: Int
59 f10 = fError
61-- HsTyVar
62fError :: Int
63fError = error "fError"
64```
66This example get error:
68```shell
69$ cabal build
70example/Main.hs:15:7: error:
71 Not in scope: type constructor or class ‘HasCallStack’
72 |
7315 | f3 :: HasCallStack => Int
74 | ^^^^^^^^^^^^
75```
77Yes, add `import GHC.Stack` to above example.
79Fix and rebuild!
81```shell
82$ cabal run example -v0
83example: fError
84CallStack (from HasCallStack):
85 error, called at example/Main.hs:47:10 in main:Main
86```
88Hmm, it is not useful. But, you will to be happy when enable this plugin.
90```cabal
91 ghc-options:
92 -fplugin=StackTrace.Plugin
93```
95```shell
96$ cabal run example -v0
97example: fError
98CallStack (from HasCallStack):
99 error, called at example/Main.hs:47:10 in main:Main
100 fError, called at example/Main.hs:43:11 in main:Main
101 f10, called at example/Main.hs:40:6 in main:Main
102 f9, called at example/Main.hs:37:11 in main:Main
103 f8, called at example/Main.hs:33:16 in main:Main
104 f7, called at example/Main.hs:29:11 in main:Main
105 f6, called at example/Main.hs:25:15 in main:Main
106 f5, called at example/Main.hs:21:8 in main:Main
107 f4, called at example/Main.hs:17:6 in main:Main
108 f3, called at example/Main.hs:13:6 in main:Main
109 f2, called at example/Main.hs:10:6 in main:Main
110 f1, called at example/Main.hs:7:14 in main:Main
111 main, called at example/Main.hs:7:1 in main:Main
112```
114Great!!!