[Haskell-cafe] two problems with Data.Binary and Data.ByteString

Don Stewart dons at galois.com
Mon Aug 25 17:28:28 EDT 2008

> On Thu, 2008-08-14 at 10:21 -0700, Don Stewart wrote:
> > > I think you're right. The Binary instances cannot and must not read more
> > > than they need to, so that gives us the behaviour that we read exactly
> > > the length of the file, but no more, and thus we never hit EOF, so we
> > > don't close the file. So yes, decode should force the tail so that it
> > > can indeed hit EOF.
> > 
> > Duncan, 
> > 
> > You're suggesting that decode and decodeFile should whnf the next cell?
> At least decodeFile should, since it doesn't give you any other access
> to the file handle otherwise.
> Does decode return the tail? I don't remember. If not it should also
> whnf it. If it does then the user can choose (they might want to do
> something else with the trailing data).

I've pushed a decodeFile that does a whnf on the tail after decoding.
If you're at the end of the file, that's sufficient to close the Handle.

You'll also need bytestring >= (note, not the one that comes by
default with ghc 6.8.x)

-- Don

More information about the Haskell-Cafe mailing list