Proposal: Debug.Trace.traceWith

David Feuer david.feuer at
Sat Feb 10 03:07:59 UTC 2018

Other another bike-shed color:

traceWith :: (a -> String) -> a -> a
traceWith f a = trace (f a) a

traceShowWith :: Show b => (a -> b) -> a -> a
traceShowWith f = traceWith (show . f)

But on the other hand, tells me that you can write

trace =<< f
trace =<< show . f

so I'm not sure how urgent these are.

On Feb 9, 2018 8:08 PM, "Kris Nuttycombe" <kris.nuttycombe at> wrote:

When using Debug.Trace for debugging, a very common operation is to prefer
to trace only some subset or function of an intermediate result. As a
consequence, I propose adding the following function to Debug.Trace:

traceWith :: (Show b) => (a -> b) -> a -> a
traceWith f a = trace (show $ f a) a

While it's trivial to define, I have found this to be one of the most
useful functions in my trace-based debugging toolkit, hence my proposal
that it be added to base. It generalizes `traceShowId` in a meaningful and
useful fashion.

As this is the first such proposal I've put forth, please let me know if
I'm doing anything wrong with it!


Kris Nuttycombe

Libraries mailing list
Libraries at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list