binary files in haskell

Simon Marlow [email protected]
Tue, 6 Feb 2001 02:00:30 -0800

> There is actually NO way with haskell 98 to portably read and write
> binary files. and many libraries which provide this feature are
> inherently non portable, (they assume a Haskell Char = C char = byte)
> which is not necisarily the case. I wrote up a proposal for a binary
> file IO mechanism to be added as a 'blessed addendum' to the 
> standard at
> best and as a commonly implmented extension (in hslibs) at least..
> my original proposal messages  to the list can be gotten from 
> although without the messages from others in the list they may
> seem out of context.

How about this slightly more general interface, which works with the new
FFI libraries, and is trivial to implement on top of the primitives in
GHC's IOExts:

	hPut :: Storable a => Handle -> a -> IO ()
	hGet :: Storable a => Handle -> IO a

Haskell 98 already defines the seek and file size operations to operate
in units of 8-bit bytes, so these don't need to be duplicated.  A
version of hGetContents on Storable objects could also be included.