<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 => String -> a -> a<br>
traceMsgIt msg x = trace (msg++show x++"\n") x<br>
<br>
traceIt :: Show a => a -> 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"><<a
moz-do-not-send="true" href="mailto:roma@ro-che.info"
target="_blank">roma@ro-che.info</a>></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>
\x -> trace x x<br>
<br>
and<br>
<br>
\x -> trace (show x) x<br>
<br>
Roman<br>
<br>
* Andreas Abel <<a moz-do-not-send="true"
href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a>>
[2013-01-21 23:31:24+0100]<br>
<div class="HOEnZb">
<div class="h5">> +1. I also had to define traceM for
the same purposes. --Andreas<br>
><br>
> On 21.01.13 6:41 PM, Chris Seaton wrote:<br>
> >Yes, I suppose that traceIO does not have the
semantics I assumed.<br>
> >Still, I think it is useful to have a trace
that one can easily insert<br>
> >into an arbitrary monad. Here's how I use it:<br>
> ><br>
> >--------<br>
> ><br>
> >import Debug.Trace<br>
> ><br>
> >main :: IO ()<br>
> >main = putStrLn $ show foo<br>
> ><br>
> >foo :: Maybe Int<br>
> >foo = do<br>
> > x <- bar 14<br>
> > traceM $ show x<br>
> > y <- bar 2<br>
> > traceM $ show y<br>
> > return $ x + y<br>
> ><br>
> >bar :: Int -> Maybe Int<br>
> >bar x = Just $ 2*x<br>
> ><br>
> >traceM :: (Monad m) => String -> m ()<br>
> >traceM message = trace message $ return ()<br>
> ><br>
> >----------<br>
> ><br>
> >I think it is cleaner and more obvious than
without the abstraction.<br>
> >Plus it is very easy to comment out. It is
really good for list<br>
> >comprehensions written in do notation, as I
often want to peek at<br>
> >intermediate values of those. I know I always
add it to my projects, so<br>
> >I thought it may be wanted in base.<br>
> ><br>
> >As Henning Thielemann said, you can use printf
or whatever with it, but<br>
> >I think that is an orthogonal issue.<br>
> ><br>
> >Regards,<br>
> ><br>
> >Chris<br>
> ><br>
> ><br>
> ><br>
> >On 21 January 2013 17:09, Herbert Valerio
Riedel <<a moz-do-not-send="true"
href="mailto:hvr@gnu.org">hvr@gnu.org</a><br>
> ><mailto:<a moz-do-not-send="true"
href="mailto:hvr@gnu.org">hvr@gnu.org</a>>>
wrote:<br>
> ><br>
> > Chris Seaton <<a moz-do-not-send="true"
href="mailto:chris@chrisseaton.com">chris@chrisseaton.com</a>
<mailto:<a moz-do-not-send="true"
href="mailto:chris@chrisseaton.com">chris@chrisseaton.com</a>>><br>
> > writes:<br>
> ><br>
> > > I use printf-style debugging a lot,
so I am always adding and<br>
> > removing<br>
> > > applications of trace. There is the
Debug.Trace.traceIO function<br>
> > that makes<br>
> > > this easy to do in the IO monad (it
just applies hPutStrLn<br>
> > stderr), but is<br>
> > > that specialisation to IO
unnecessary?<br>
> > ><br>
> > > I find myself always using this
utility function:<br>
> > ><br>
> > > traceM :: (Monad m) => String
-> m ()<br>
> > > traceM message = trace message $
return ()<br>
> > ><br>
> > > Which can be used to implement
traceIO.<br>
> > ><br>
> > > traceIO :: String -> IO ()<br>
> > > traceIO = traceM<br>
> ><br>
> > btw, that wouldn't have the same semantics
as the existing<br>
> > `Debug.Trace.traceIO` which is more or less
something similiar to a<br>
> > `hPutStrLn stderr` whose side-effect gets
triggered at monad-execution<br>
> > time, whereas the side-effect of `traceM`
occurs at monad-construction<br>
> > time; consider the following program:<br>
> ><br>
> > --8<---------------cut
here---------------start------------->8---<br>
> > import Control.Monad<br>
> > import Debug.Trace<br>
> ><br>
> > traceM :: (Monad m) => String -> m ()<br>
> > traceM message = trace message $ return ()<br>
> ><br>
> > traceIO' :: String -> IO ()<br>
> > traceIO' = traceM<br>
> ><br>
> > main = replicateM_ 5 $ do<br>
> > trace1<br>
> > trace2<br>
> > where<br>
> > trace1 = traceIO' "trace1"<br>
> > trace2 = traceIO "trace2"<br>
> > --8<---------------cut
here---------------end--------------->8---<br>
> ><br>
> > when run via runghc (or compiled with -O0)
for GHC 7.6, this emits<br>
> ><br>
> > --8<---------------cut
here---------------start------------->8---<br>
> > trace1<br>
> > trace2<br>
> > trace2<br>
> > trace2<br>
> > trace2<br>
> > trace2<br>
> > --8<---------------cut
here---------------end--------------->8---<br>
> ><br>
> > only when using -O1 or -O2 the output
results in<br>
> ><br>
> > --8<---------------cut
here---------------start------------->8---<br>
> > trace1<br>
> > trace2<br>
> > trace1<br>
> > trace2<br>
> > trace1<br>
> > trace2<br>
> > trace1<br>
> > trace2<br>
> > trace1<br>
> > trace2<br>
> > --8<---------------cut
here---------------end--------------->8---<br>
> ><br>
> > (I'm guessing this due to `trace1` being
inlined for -O1/-O2 -- but I<br>
> > haven't checked)<br>
> ><br>
> > cheers,<br>
> > hvr<br>
> ><br>
> ><br>
> ><br>
> ><br>
> >_______________________________________________<br>
> >Libraries mailing list<br>
> ><a moz-do-not-send="true"
href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
> ><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>
> ><br>
><br>
> --<br>
> Andreas Abel <>< Du bist der
geliebte Mensch.<br>
><br>
> Theoretical Computer Science, University of Munich<br>
> Oettingenstr. 67, D-80538 Munich, GERMANY<br>
><br>
> <a moz-do-not-send="true"
href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a><br>
> <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>
><br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a moz-do-not-send="true"
href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
> <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>