<div dir="ltr">That would have been useful to know three weeks ago.<div style>Better late than never I guess.</div><div style>Thanks.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 15, 2013 at 1:24 AM, Kim-Ee Yeoh <span dir="ltr">&lt;<a href="mailto:ky3@atamo.com" target="_blank">ky3@atamo.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 class="im">On Fri, Mar 15, 2013 at 5:52 AM, Jacek Dudek &lt;<a href="mailto:jzdudek@gmail.com">jzdudek@gmail.com</a>&gt; wrote:<br>


&gt; readFile fileName &gt;&gt;= \ contents -&gt;<br>
&gt; writeFile fileName (f contents)<br>
<br>
</div>You&#39;re reading and writing to the /same/ file back to back. With Lazy<br>
I/O. Those two just don&#39;t mix.<br>
<br>
The &quot;permission denied&quot; probably stems from the attempted write<br>
clashing with the previous exclusive read handle.<br>
<div class="im"><br>
&gt; I thought lazy IO was implemented in such a way that you were safe to<br>
&gt; INTERPRET the IO action as having been fully performed.<br>
<br>
</div>Nope.<br>
<br>
The usual gotcha lying for the unwary is<br>
<br>
do<br>
    h &lt;- openFile fname1 ReadMode<br>
    s &lt;- hGetContents h<br>
    hClose h<br>
    writeFile fname2 s<br>
<br>
In the case fname1==fname2, a different surprise lies in store as<br>
you&#39;ve just witnessed.<br>
<br>
Importing System.IO.Strict from the strict package should fix all of the above.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Kim-Ee<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>