diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2019-05-20 17:36:18 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-05-27 10:06:29 -0400 |
commit | 723216e3ee8d5d535ca74b67748453f948d73d42 (patch) | |
tree | e579b9f68ab229a5f5be86beafd75bea39ace7ef /compiler/utils/Outputable.hs | |
parent | 1f51aad656444c667cf1dd22605ee65e931985c7 (diff) | |
download | haskell-723216e3ee8d5d535ca74b67748453f948d73d42.tar.gz |
Add a pprTraceWith function
Diffstat (limited to 'compiler/utils/Outputable.hs')
-rw-r--r-- | compiler/utils/Outputable.hs | 12 |
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. |