[Haskell-cafe] getContents and lazy evaluation
droundy at darcs.net
Wed Sep 6 09:37:21 EDT 2006
On Fri, Sep 01, 2006 at 11:47:20PM +0100, Duncan Coutts wrote:
> On Fri, 2006-09-01 at 17:36 -0400, Robert Dockins wrote:
> > Well, AFAIK, the behavior is officially undefined, which is my
> > real beef. I agree that it _should_ throw an exception.
> Ah, I had thought it was defined to simply truncate. It being
> undefined isn't good. It seems that it would be straightforward to
> define it to have the truncation behaviour. If Haskell-prime gets
> imprecise exceptions then that could be changed.
Fortunately, the undefined behavior in this case is unrelated to the
lazy IO. On windows, the removal of the file will fail, while on
posix systems there won't be any failure at all. The same behavior
would show up if you opened the file for non-lazy reading, and tried
to read part of the file, then delete it, then read the rest.
The "undefinedness" in this example, isn't in the haskell language,
but in the filesystem semantics, and that's not something we want the
language specifying (since it's something over which it has no
control). Lazy IO definitely works much more nicely with posix
filesystems, but that's unsurprising, since posix filesystem semantics
are much nicer than those of Windows.
More information about the Haskell-Cafe