<div dir="ltr"><div>Hi,<br><br>In the first example the traceShows are only called as a side effect of evaluating the IO expression (traceShow "Bla" $ do traceShow "Bloe" runit) which happens only once (runit is a top-level binding). I assume that for the second example GHC lifts (traceShow "Num" print 2) out of the do block and similarly evaluates it only once. <br><br>The traceShow "Bloe" is not lifted out of there because it's under a lambda. E.g. if you do this instead:<br><br>runit :: IO ()<br>runit = traceShow "Bla" $ do<br>  traceShow "Num" (print 2)<br>  traceShow "Bloe" runit<br><br></div><div>You get <br><br>"Bla"<br>"Num"<br>2<br>"Bloe"<br>2<br>2<br>2<br>2<br>...<br></div><div><br><br></div><div>Jacco<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-28 16:16 GMT+01:00 Jurriaan Hage <span dir="ltr"><<a href="mailto:J.Hage@uu.nl" target="_blank">J.Hage@uu.nl</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We had a strange phenomenon while debugging a large compiler.<br>
This is the smallest example, but we have seen this behavior in our own monad.<br>
<br>
module TracEx where<br>
<br>
import Debug.Trace<br>
<br>
runit :: IO ()<br>
runit = traceShow "Bla" $ do<br>
  traceShow "Bloe” runit<br>
<br>
<br>
and this generates<br>
Bla<br>
Bloe<br>
<br>
and then it hangs. Nothing else is generated.<br>
We are guessing this has to do with optimisations of some kind.<br>
<br>
And what about<br>
<br>
runit :: IO ()<br>
runit = traceShow "Bla" $ do<br>
  n <- traceShow "Num" print 2<br>
  traceShow "Bloe” runit<br>
<br>
Now we get<br>
Bla<br>
Num<br>
2<br>
Bloe<br>
2<br>
Bloe<br>
2<br>
…<br>
No more Bla and no more Num.<br>
<br>
Any ideas whether this is a bug or a feature?<br>
<br>
Jur and Tibor<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br></div>