summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2019-05-20 17:36:18 +0200
committerSebastian Graf <sgraf1337@gmail.com>2019-05-27 01:37:43 -0400
commit1b6080633ad5a080fd327e867f3566edb7e758a3 (patch)
tree8cc2494ef6eccbd416f0ea73a6401c85719aee3c
parent2d0cf6252957b8980d89481ecd0b79891da4b14b (diff)
downloadhaskell-wip/ppr-trace-with.tar.gz
Add a pprTraceWith functionwip/ppr-trace-with
-rw-r--r--compiler/utils/Outputable.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs
index fee257d98a..47b0d67449 100644
--- a/compiler/utils/Outputable.hs
+++ b/compiler/utils/Outputable.hs
@@ -81,8 +81,8 @@ module Outputable (
-- * Error handling and debugging utilities
pprPanic, pprSorry, assertPprPanic, pprPgmError,
- pprTrace, pprTraceDebug, pprTraceIt, warnPprTrace, pprSTrace,
- pprTraceException, pprTraceM,
+ pprTrace, pprTraceDebug, pprTraceWith, pprTraceIt, warnPprTrace,
+ pprSTrace, pprTraceException, pprTraceM,
trace, pgmError, panic, sorry, assertPanic,
pprDebugAndThen, callStackDoc,
) where
@@ -1196,9 +1196,15 @@ pprTrace str doc x
pprTraceM :: Applicative f => String -> SDoc -> f ()
pprTraceM str doc = pprTrace str doc (pure ())
+-- | @pprTraceWith desc f x@ is equivalent to @pprTrace desc (f x) x@.
+-- This allows you to print details from the returned value as well as from
+-- ambient variables.
+pprTraceWith :: Outputable a => String -> (a -> SDoc) -> a -> a
+pprTraceWith desc f x = pprTrace desc (f x) x
+
-- | @pprTraceIt desc x@ is equivalent to @pprTrace desc (ppr x) x@
pprTraceIt :: Outputable a => String -> a -> a
-pprTraceIt desc x = pprTrace desc (ppr x) x
+pprTraceIt desc x = pprTraceWith desc ppr x
-- | @pprTraceException desc x action@ runs action, printing a message
-- if it throws an exception.