From 9390321fade9e82827f9f231d69de741a115685f Mon Sep 17 00:00:00 2001 From: Sebastian Graf <sebastian.graf@kit.edu> Date: Mon, 20 May 2019 17:36:18 +0200 Subject: [PATCH] Add a pprTraceWith function --- compiler/utils/Outputable.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index fee257d98a5..47b0d674490 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. -- GitLab