Note that traceM won&#39;t work correctly for monads that are not strict in the first argument of &gt;&gt;=, e.g. the Identity monad.<div><br><div>For example, this will not print anything: runIdentity $ traceM &quot;test&quot; &gt;&gt; return ()</div>
<div><br><div class="gmail_quote">On Mon, Jan 21, 2013 at 11:48 AM, Chris Seaton <span dir="ltr">&lt;<a href="mailto:chris@chrisseaton.com" target="_blank">chris@chrisseaton.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I use printf-style debugging a lot, so I am always adding and removing applications of trace. There is the Debug.Trace.traceIO function that makes this easy to do in the IO monad (it just applies <span style>hPutStrLn stderr), but is that specialisation to IO </span>unnecessary?<div>

<br></div><div>I find myself always using this utility function:</div><div><br></div><div><div>traceM :: (Monad m) =&gt; String -&gt; m ()</div><div>traceM message = trace message $ return ()</div><div><br>
</div><div>Which can be used to implement traceIO.</div><div><br></div><div><div>traceIO :: String -&gt; IO ()</div><div>traceIO = traceM</div></div><div><br></div><div>That way I can traceM in whatever monad I am in. It is easier to add and remove an application of trace, because I do not have to wrap it around something, and I do not have to remember the return. Of course, you are still subject to however your monad chooses to order the execution of these traces, but that is what people expect when using trace.</div>

<div><br></div><div>Would traceM be a wanted addition to Debug.Trace?</div><div><br></div><div>Regards,</div><div><br></div><div>Chris Seaton</div><div><div><br></div></div></div>
</div>
<br>_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div></div>