[Haskell-beginners] Confused about lazy IO
gesh at gesh.uni.cx
Sun Mar 17 15:10:37 CET 2013
That would have been useful to know three weeks ago.
Better late than never I guess.
On Fri, Mar 15, 2013 at 1:24 AM, Kim-Ee Yeoh <ky3 at atamo.com> wrote:
> On Fri, Mar 15, 2013 at 5:52 AM, Jacek Dudek <jzdudek at gmail.com> wrote:
> > readFile fileName >>= \ contents ->
> > writeFile fileName (f contents)
> You're reading and writing to the /same/ file back to back. With Lazy
> I/O. Those two just don't mix.
> The "permission denied" probably stems from the attempted write
> clashing with the previous exclusive read handle.
> > I thought lazy IO was implemented in such a way that you were safe to
> > INTERPRET the IO action as having been fully performed.
> The usual gotcha lying for the unwary is
> h <- openFile fname1 ReadMode
> s <- hGetContents h
> hClose h
> writeFile fname2 s
> In the case fname1==fname2, a different surprise lies in store as
> you've just witnessed.
> Importing System.IO.Strict from the strict package should fix all of the
> -- Kim-Ee
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners