<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">+1 I've used all three functions as
      well (and traceM probably the most).<br>
      <br>
      As for the other two, the names are probably not the best, but
      I've used these versions:<br>
      <meta charset="utf-8">
      <br>
      traceMsgIt :: Show a =&gt; String -&gt; a -&gt; a<br>
      traceMsgIt msg x = trace (msg++show x++"\n") x<br>
      <br>
      traceIt :: Show a =&gt; a -&gt; a<br>
      traceIt x = traceMsgIt "\nTraceIt:\n" x<br>
      <br>
      --Gershom<br>
      <br>
      On 1/24/13 10:14 AM, Chris Seaton wrote:<br>
    </div>
    <blockquote
cite="mid:CAJsFBcTVeWCuskfgpqN3kxWw+W9VE5S7i-CgFULTx+WUkcnM3Q@mail.gmail.com"
      type="cite">
      <div dir="ltr">What do you call these functions? I'll put them all
        into a patch and open a feature request for them all in one go.
        <div><br>
        </div>
        <div>Chris</div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">
          On 21 January 2013 22:40, Roman Cheplyaka <span dir="ltr">&lt;<a
              moz-do-not-send="true" href="mailto:roma@ro-che.info"
              target="_blank">roma@ro-che.info</a>&gt;</span> wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            While we're at it, the trace functions I miss are<br>
            <br>
            &nbsp; \x -&gt; trace x x<br>
            <br>
            and<br>
            <br>
            &nbsp; \x -&gt; trace (show x) x<br>
            <br>
            Roman<br>
            <br>
            * Andreas Abel &lt;<a moz-do-not-send="true"
              href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a>&gt;
            [2013-01-21 23:31:24+0100]<br>
            <div class="HOEnZb">
              <div class="h5">&gt; +1. &nbsp;I also had to define traceM for
                the same purposes. --Andreas<br>
                &gt;<br>
                &gt; On 21.01.13 6:41 PM, Chris Seaton wrote:<br>
                &gt; &gt;Yes, I suppose that traceIO does not have the
                semantics I assumed.<br>
                &gt; &gt;Still, I think it is useful to have a trace
                that one can easily insert<br>
                &gt; &gt;into an arbitrary monad. Here's how I use it:<br>
                &gt; &gt;<br>
                &gt; &gt;--------<br>
                &gt; &gt;<br>
                &gt; &gt;import Debug.Trace<br>
                &gt; &gt;<br>
                &gt; &gt;main :: IO ()<br>
                &gt; &gt;main = putStrLn $ show foo<br>
                &gt; &gt;<br>
                &gt; &gt;foo :: Maybe Int<br>
                &gt; &gt;foo = do<br>
                &gt; &gt; &nbsp; &nbsp; x &lt;- bar 14<br>
                &gt; &gt; &nbsp; &nbsp; traceM $ show x<br>
                &gt; &gt; &nbsp; &nbsp; y &lt;- bar 2<br>
                &gt; &gt; &nbsp; &nbsp; traceM $ show y<br>
                &gt; &gt; &nbsp; &nbsp; return $ x + y<br>
                &gt; &gt;<br>
                &gt; &gt;bar :: Int -&gt; Maybe Int<br>
                &gt; &gt;bar x = Just $ 2*x<br>
                &gt; &gt;<br>
                &gt; &gt;traceM :: (Monad m) =&gt; String -&gt; m ()<br>
                &gt; &gt;traceM message = trace message $ return ()<br>
                &gt; &gt;<br>
                &gt; &gt;----------<br>
                &gt; &gt;<br>
                &gt; &gt;I think it is cleaner and more obvious than
                without the abstraction.<br>
                &gt; &gt;Plus it is very easy to comment out. It is
                really good for list<br>
                &gt; &gt;comprehensions written in do notation, as I
                often want to peek at<br>
                &gt; &gt;intermediate values of those. I know I always
                add it to my projects, so<br>
                &gt; &gt;I thought it may be wanted in base.<br>
                &gt; &gt;<br>
                &gt; &gt;As Henning Thielemann said, you can use printf
                or whatever with it, but<br>
                &gt; &gt;I think that is an orthogonal issue.<br>
                &gt; &gt;<br>
                &gt; &gt;Regards,<br>
                &gt; &gt;<br>
                &gt; &gt;Chris<br>
                &gt; &gt;<br>
                &gt; &gt;<br>
                &gt; &gt;<br>
                &gt; &gt;On 21 January 2013 17:09, Herbert Valerio
                Riedel &lt;<a moz-do-not-send="true"
                  href="mailto:hvr@gnu.org">hvr@gnu.org</a><br>
                &gt; &gt;&lt;mailto:<a moz-do-not-send="true"
                  href="mailto:hvr@gnu.org">hvr@gnu.org</a>&gt;&gt;
                wrote:<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;Chris Seaton &lt;<a moz-do-not-send="true"
                  href="mailto:chris@chrisseaton.com">chris@chrisseaton.com</a>
                &lt;mailto:<a moz-do-not-send="true"
                  href="mailto:chris@chrisseaton.com">chris@chrisseaton.com</a>&gt;&gt;<br>
                &gt; &gt; &nbsp; &nbsp;writes:<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp; &gt; I use printf-style debugging a lot,
                so I am always adding and<br>
                &gt; &gt; &nbsp; &nbsp;removing<br>
                &gt; &gt; &nbsp; &nbsp; &gt; applications of trace. There is the
                Debug.Trace.traceIO function<br>
                &gt; &gt; &nbsp; &nbsp;that makes<br>
                &gt; &gt; &nbsp; &nbsp; &gt; this easy to do in the IO monad (it
                just applies hPutStrLn<br>
                &gt; &gt; &nbsp; &nbsp;stderr), but is<br>
                &gt; &gt; &nbsp; &nbsp; &gt; that specialisation to IO
                unnecessary?<br>
                &gt; &gt; &nbsp; &nbsp; &gt;<br>
                &gt; &gt; &nbsp; &nbsp; &gt; I find myself always using this
                utility function:<br>
                &gt; &gt; &nbsp; &nbsp; &gt;<br>
                &gt; &gt; &nbsp; &nbsp; &gt; traceM :: (Monad m) =&gt; String
                -&gt; m ()<br>
                &gt; &gt; &nbsp; &nbsp; &gt; traceM message = trace message $
                return ()<br>
                &gt; &gt; &nbsp; &nbsp; &gt;<br>
                &gt; &gt; &nbsp; &nbsp; &gt; Which can be used to implement
                traceIO.<br>
                &gt; &gt; &nbsp; &nbsp; &gt;<br>
                &gt; &gt; &nbsp; &nbsp; &gt; traceIO :: String -&gt; IO ()<br>
                &gt; &gt; &nbsp; &nbsp; &gt; traceIO = traceM<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;btw, that wouldn't have the same semantics
                as the existing<br>
                &gt; &gt; &nbsp; &nbsp;`Debug.Trace.traceIO` which is more or less
                something similiar to a<br>
                &gt; &gt; &nbsp; &nbsp;`hPutStrLn stderr` whose side-effect gets
                triggered at monad-execution<br>
                &gt; &gt; &nbsp; &nbsp;time, whereas the side-effect of `traceM`
                occurs at monad-construction<br>
                &gt; &gt; &nbsp; &nbsp;time; consider the following program:<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;--8&lt;---------------cut
                here---------------start-------------&gt;8---<br>
                &gt; &gt; &nbsp; &nbsp;import Control.Monad<br>
                &gt; &gt; &nbsp; &nbsp;import Debug.Trace<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;traceM :: (Monad m) =&gt; String -&gt; m ()<br>
                &gt; &gt; &nbsp; &nbsp;traceM message = trace message $ return ()<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;traceIO' :: String -&gt; IO ()<br>
                &gt; &gt; &nbsp; &nbsp;traceIO' = traceM<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;main = replicateM_ 5 $ do<br>
                &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp; &nbsp; where<br>
                &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; trace1 = traceIO' "trace1"<br>
                &gt; &gt; &nbsp; &nbsp; &nbsp; &nbsp; trace2 = traceIO &nbsp;"trace2"<br>
                &gt; &gt; &nbsp; &nbsp;--8&lt;---------------cut
                here---------------end---------------&gt;8---<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;when run via runghc (or compiled with -O0)
                for GHC 7.6, this emits<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;--8&lt;---------------cut
                here---------------start-------------&gt;8---<br>
                &gt; &gt; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;--8&lt;---------------cut
                here---------------end---------------&gt;8---<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;only when using -O1 or -O2 the output
                results in<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;--8&lt;---------------cut
                here---------------start-------------&gt;8---<br>
                &gt; &gt; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;trace1<br>
                &gt; &gt; &nbsp; &nbsp;trace2<br>
                &gt; &gt; &nbsp; &nbsp;--8&lt;---------------cut
                here---------------end---------------&gt;8---<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;(I'm guessing this due to `trace1` being
                inlined for -O1/-O2 -- but I<br>
                &gt; &gt; &nbsp; &nbsp;haven't checked)<br>
                &gt; &gt;<br>
                &gt; &gt; &nbsp; &nbsp;cheers,<br>
                &gt; &gt; &nbsp; &nbsp; &nbsp; hvr<br>
                &gt; &gt;<br>
                &gt; &gt;<br>
                &gt; &gt;<br>
                &gt; &gt;<br>
                &gt; &gt;_______________________________________________<br>
                &gt; &gt;Libraries mailing list<br>
                &gt; &gt;<a moz-do-not-send="true"
                  href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
                &gt; &gt;<a moz-do-not-send="true"
                  href="http://www.haskell.org/mailman/listinfo/libraries"
                  target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
                &gt; &gt;<br>
                &gt;<br>
                &gt; --<br>
                &gt; Andreas Abel &nbsp;&lt;&gt;&lt; &nbsp; &nbsp; &nbsp;Du bist der
                geliebte Mensch.<br>
                &gt;<br>
                &gt; Theoretical Computer Science, University of Munich<br>
                &gt; Oettingenstr. 67, D-80538 Munich, GERMANY<br>
                &gt;<br>
                &gt; <a moz-do-not-send="true"
                  href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a><br>
                &gt; <a moz-do-not-send="true"
                  href="http://www2.tcs.ifi.lmu.de/%7Eabel/"
                  target="_blank">http://www2.tcs.ifi.lmu.de/~abel/</a><br>
                &gt;<br>
                &gt; _______________________________________________<br>
                &gt; Libraries mailing list<br>
                &gt; <a moz-do-not-send="true"
                  href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
                &gt; <a moz-do-not-send="true"
                  href="http://www.haskell.org/mailman/listinfo/libraries"
                  target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Libraries mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libraries@haskell.org">Libraries@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/libraries">http://www.haskell.org/mailman/listinfo/libraries</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>