<br><font size=2 face="sans-serif">However, when I actually tried this
out, I couldn't get it to compile. </font>
<br>
<br><font size=2 face="sans-serif">So I wound up back with trace. This
does compile, and I think it does pretty much what we want in a &quot;noninvasive&quot;
way, using unsafePerformIO via trace.</font>
<br>
<br><font size=2 face="Courier New">import Debug.Trace</font>
<br>
<br><font size=2 face="Courier New">t = foldr (+) 0 ( monitorprogress f
[1..10000] ) </font>
<br>
<br><font size=2 face="Courier New">monitorprogress f xs = map g $ zip
[1..] xs</font>
<br><font size=2 face="Courier New">&nbsp; where g (i,a) | f i == True
= trace (show i) a</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; | otherwise = a </font>
<br>
<br><font size=2 face="Courier New">f x | x `mod` 1000 == 0 = True</font>
<br><font size=2 face="Courier New">&nbsp; &nbsp; | otherwise = False</font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Thomas Hartman/ext/dbcom@DBAmericas</b>
</font>
<br><font size=1 face="sans-serif">Sent by: haskell-cafe-bounces@haskell.org</font>
<p><font size=1 face="sans-serif">11/29/2007 10:43 AM</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">haskell-cafe@haskell.org, droundy@darcs.net</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [Haskell-cafe] Progress indications</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2 face="sans-serif"><br>
Obviously heaps better than what I initially proposed.</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
However, I would argue to go boldly with unsafePerformIO, which is the
same thing Debug.Trace uses</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
http://darcs.haskell.org/ghc-6.6/packages/base/Debug/Trace.hs</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
since we are after debug.trace -like behavior.</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
In particular, you wouldn't be able to use the unsafeInterleaveIO version
to do a progress indicator for the function I initially proposed</font><font size=3>
<br>
</font><tt><font size=2><br>
&gt; t = foldr (+) 0 [1..10000]</font></tt><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
since your lift would wind up being lifted into IO. But you would be able
to use the unsafePerformIO version, just like in what I initially proposed
you could use trace.</font><font size=3> <br>
</font><tt><font size=2><br>
t = foldr (+) 0 ( lessSafeMonitoryProgress f [1..10000] )</font></tt><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp;where f i | i mod 1000 == 0 = (putStrLn . show ) i</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | otherwise
= return ()</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp;<br>
Make sense?</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
thomas.</font><font size=3> <br>
<br>
<br>
<br>
</font>
<table width=100%>
<tr valign=top>
<td width=48%><font size=1 face="sans-serif"><b>David Roundy &lt;droundy@darcs.net&gt;</b>
<br>
Sent by: haskell-cafe-bounces@haskell.org</font><font size=3> </font>
<p><font size=1 face="sans-serif">11/28/2007 06:16 PM</font><font size=3>
</font>
<td width=51%>
<br>
<table width=100%>
<tr valign=top>
<td width=17%>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td width=82%><font size=1 face="sans-serif">haskell-cafe@haskell.org</font><font size=3>
</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [Haskell-cafe] Progress indications</font></table>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=50%>
<td width=50%></table>
<br></table>
<br><font size=3><br>
<br>
</font><tt><font size=2><br>
On Wed, Nov 28, 2007 at 05:58:07PM -0500, Thomas Hartman wrote:<br>
&gt; maybe Debug.Trace? like...<br>
&gt; <br>
&gt; import Debug.Trace<br>
&gt; <br>
&gt; t = foldr debugf 0 [1..10000]<br>
&gt; <br>
&gt; f :: Int -&gt; Int -&gt; Int<br>
&gt; f = (+)<br>
&gt; <br>
&gt; -- same typesig as f<br>
&gt; debugf :: Int -&gt; Int -&gt; Int<br>
&gt; debugf x y | y `mod` 1000 == 0 = x + (trace (show y) y)<br>
&gt; debugf x y = x + y<br>
<br>
Or, more flexibly:<br>
<br>
import System.IO.Unsafe ( unsafeInterleaveIO )<br>
<br>
monitorProgress :: (Int -&gt; IO ()) -&gt; [a] -&gt; IO [a]<br>
monitorProgress f xs = mapM f' $ zip [0..] xs<br>
 &nbsp;where f' (n,x) = unsafeInterleaveIO (f n &gt;&gt; return x)<br>
<br>
You could, of course, make this a function<br>
<br>
lessSafeMonitoryProgress :: (Int -&gt; IO ()) -&gt; [a] -&gt; [a]<br>
<br>
by using unsafePerformIO instead of unsafeInterleaveIO, but that seems<br>
slightly scary to me.<br>
<br>
In any case, you can stick this on whichever of the lists you want to<br>
monitor the progress of.<br>
-- <br>
David Roundy<br>
Department of Physics<br>
Oregon State University<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
Haskell-Cafe@haskell.org<br>
http://www.haskell.org/mailman/listinfo/haskell-cafe</font></tt><font size=3><br>
<br>
</font><font size=2 face="sans-serif"><br>
---</font><font size=3><br>
</font><font size=2 face="sans-serif"><br>
This e-mail may contain confidential and/or privileged information. If
you <br>
are not the intended recipient (or have received this e-mail in error)
<br>
please notify the sender immediately and destroy this e-mail. Any <br>
unauthorized copying, disclosure or distribution of the material in this
<br>
e-mail is strictly forbidden.</font><tt><font size=2>_______________________________________________<br>
Haskell-Cafe mailing list<br>
Haskell-Cafe@haskell.org<br>
http://www.haskell.org/mailman/listinfo/haskell-cafe<br>
</font></tt>
<br>
<br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">---</span><br>
<br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">This e-mail may contain confidential and/or privileged information. If you </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">are not the intended recipient (or have received this e-mail in error) </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">please notify the sender immediately and destroy this e-mail. Any </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">unauthorized copying, disclosure or distribution of the material in this </span><br>
<span style="font-family:sans-serif,helvetica; font-size:10pt; color:#000000">e-mail is strictly forbidden.</span><br>