[Haskell-cafe] Data.Binary, strict reading

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Feb 25 18:44:10 EST 2009


On Wed, 2009-02-25 at 17:15 +0000, Neil Mitchell wrote:
> Hi,
> 
> I want to read a file using Data.Binary, and I want to read the file
> strictly - i.e. when I leave the read file I want to guarantee the
> handle is closed. The reason is that (possibly immediately after) I
> need to write to the file. The following is the magic I need to use -
> is it all necessary, is it guaranteed correct, should I use something
> else?
> 
>         src <- decodeFile "_make/_make"
>         Map.size mp `seq` performGC

I suggest you use withFile instead and decode from the Handle that gives
you (via hGetContents) rather than decodeFile from the file name. That
makes it much clearer. Of course you have to avoid doing lazy stuff, but
that should be ok, Binary is strict in reading by default.

Duncan



More information about the Haskell-Cafe mailing list