<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Feb 10, 2018 at 6:48 AM, Michael Sloan <span dir="ltr"><<a href="mailto:mgsloan@gmail.com" target="_blank">mgsloan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I often define<div dir="auto"><br></div><div dir="auto">tracer prefix x = trace (prefix ++ ": " ++ show x) x</div></div></blockquote><div><br></div><div>I also have `traceWithPrefix :: (Show b) -> String -> (a -> b) -> a -> a` defined, for the same reason, so I absolutely support adding that as well.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto">A bit arbitrary with the choice of ": ", but quite convenient. The with variant would be</div><div dir="auto"><br></div><div dir="auto">tracerWith prefix f x = trace (prefix ++ ": " ++ show (f x)) x</div></div></blockquote><div><br></div><div>The definition I use is simply </div><div><br></div><div>traceWithPrefix p f a = trace (p ++ show (f a)) a</div><div><br></div><div><br class="gmail-Apple-interchange-newline">On Fri, Feb 9, 2018 at 7:07 PM, David Feuer<span> </span><span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank" style="color:rgb(17,85,204)">david.feuer@gmail.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Other another bike-shed color:</div><div dir="auto"><br></div><div dir="auto"><div dir="auto" style="font-family:sans-serif">traceWith :: (a -> String) -> a -> a</div><div dir="auto" style="font-family:sans-serif">traceWith f a = trace (f a) a</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif"><div dir="auto" style="color:rgb(34,34,34);font-family:sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">traceShowWith :: Show b => (a -> b) -> a -> a</div><div dir="auto" style="color:rgb(34,34,34);font-family:sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">traceShowWith f = traceWith (show . f)</div></div></div></div></blockquote><div><br></div><div>Is there some situation where the `Show String` instance wouldn't be in scope? If `b` is `String` it works out just fine, so the first definition you gave here seems superfluous.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto"><div dir="auto" style="font-family:sans-serif"><div dir="auto" style="color:rgb(34,34,34);font-family:sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">But on the other hand,<span> </span><a href="http://pointfree.io/" target="_blank" style="color:rgb(17,85,204)">pointfree.io</a><span> </span>tells me that you can write</div><div dir="auto" style="color:rgb(34,34,34);font-family:sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div dir="auto" style="color:rgb(34,34,34);font-family:sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">trace =<< f</div><div dir="auto" style="color:rgb(34,34,34);font-family:sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">trace =<< show . f</div><br class="gmail-Apple-interchange-newline"></div></div></div></blockquote> </div><div>That's... remarkably clever, so clever that it never occurred to me in 4 years of writing Haskell. :) I see your point, but jumping to the `Monad Reader` instance is a bit surprising. At very least, maybe this approach ought to be documented in the module. Thanks for pointing it out!</div><div><br></div><div>So, a question for all: if I were to want to create a pull request to add these functions (traceWith and traceWithPrefix) where would I go to do so?</div><div><br></div><div>Thanks,</div><div><br></div><div>Kris</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div class="gmail_extra" dir="auto"><br><div class="gmail_quote"><div><div class="h5">On Feb 9, 2018 5:09 PM, "Kris Nuttycombe" <<a href="mailto:kris.nuttycombe@gmail.com" target="_blank">kris.nuttycombe@gmail.com</a>> wrote:<br type="attribution"></div></div><blockquote class="m_-1448476825673201598quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">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:<div><br></div><div><div>traceWith :: (Show b) => (a -> b) -> a -> a</div><div>traceWith f a = trace (show $ f a) a</div><div><br></div></div><div>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. </div><div><br></div><div>As this is the first such proposal I've put forth, please let me know if I'm doing anything wrong with it!</div><div><br></div><div>Thanks,</div><div><br></div><div>Kris Nuttycombe</div></div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/libraries</a><br>
<br></span></blockquote></div><br></div></div>
</blockquote></div><br></div></div>