Debian Codegraph @

src/TextShow/Debug/Trace/TH.hs

raw
1 {-# LANGUAGE TemplateHaskell #-}
2 {-|
3 Module: TextShow.Debug.Trace.TH
4 Copyright: (C) 2014-2017 Ryan Scott
5 License: BSD-style (see the file LICENSE)
6 Maintainer: Ryan Scott
7 Stability: Provisional
8 Portability: GHC
9
10 Functions that splice traces into source code which take an arbitrary data type or
11 data family instance as an argument (even if it is not an instance of @TextShow@). You
12 need to enable the @TemplateHaskell@ language extension in order to use this module.
13
14 /Since: 2/
15 -}
16 module TextShow.Debug.Trace.TH (
17 makeTraceTextShow
18 , makeTraceTextShowId
19 , makeTraceTextShowM
20 ) where
21
22 import Language.Haskell.TH.Syntax (Name, Q, Exp)
23
24 import TextShow.Debug.Trace
25 import TextShow.TH.Internal (makeShowt)
26
27 -- | Generates a lambda expression which behaves like 'traceTextShow' (without
28 -- requiring a @TextShow@ instance).
29 --
30 -- /Since: 2/
31 makeTraceTextShow :: Name -> Q Exp
32 makeTraceTextShow name = [| tracet . $(makeShowt name) |]
33
34 -- | Generates a lambda expression which behaves like 'traceTextShowId' (without
35 -- requiring a @TextShow@ instance).
36 --
37 -- /Since: 2/
38 makeTraceTextShowId :: Name -> Q Exp
39 makeTraceTextShowId name = [| \a -> tracet ($(makeShowt name) a) a |]
40
41 -- | Generates a lambda expression which behaves like 'traceTextShowM' (without
42 -- requiring a @TextShow@ instance).
43 --
44 -- /Since: 2/
45 makeTraceTextShowM :: Name -> Q Exp
46 makeTraceTextShowM name = [| tracetM . $(makeShowt name) |]