On Tue, Jul 01, 2008 at 10:22:35AM +0000, Joachim Breitner wrote:
> Hi,
> 
> Am Dienstag, den 01.07.2008, 11:53 +0200 schrieb Ketil Malde:
> > Joachim Breitner <[EMAIL PROTECTED]> writes:
> > 
> > >> 1) unsafeInterleaveIO seems like a big hammer to use for this problem,
> > >> and there are a lot of gotchas involved that you may not have fully
> > >> thought out.  But you do meet the main criteria (file being read is
> > >> assumed to be constant for a single run of the program).
> > 
> > > Any other gotcha? 
> > 
> > The one that springs to mind is that you might run out of file
> > handles. At least on Linux, that's a precious resource.
> 
> but at least then, (unsafeInterleaveIO readFile) is actually better than
> (readFile), because if I consume the files in sequence and complete,
> they will be opened and closed in sequence with the first one, but be
> opened all at once with the second. At least it won’t be worse, because
> the file will not be closed later, and possibly opened later.

Indeed, the best option (in my opinion) would be

unsafeInterleaveIO readFileStrict

(where you might need to write readFileStrict).  In darcs, we use lazy IO a
lot, but never lazily read a file, precisely due to the open file handle
issue.  This works pretty well, and your scenario is precisely the one in
which unsafeInterleaveIO shines.

David

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to