binary files in haskell

Olaf Chitil olaf@cs.york.ac.uk
Tue, 06 Feb 2001 11:32:30 +0000


Simon Marlow wrote:

> > http://www.ugcs.caltech.edu/~john/computer/haskell/
> 
> 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

What about endianess? In which format are Floats or even just Bools
stored? For a file which probably shall be read from different machines
this is not clear at all.

I think John is right that there needs to be a primitive interface for
just writing bytes. You can then build anything more complicated on top
(probably different high-level ones for different purposes).

I just see one problem with John's proposal: the type Byte. It is
completely useless if you don't have operations that go with it;
bit-operations and conversions to and from Int. The FFI already defines
such a type: Word8. So I suggest that the binary IO library explicitely
reads and writes Word8's.

Cheers,
Olaf

-- 
OLAF CHITIL, 
 Dept. of Computer Science, University of York, York YO10 5DD, UK. 
 URL: http://www.cs.york.ac.uk/~olaf/
 Tel: +44 1904 434756; Fax: +44 1904 432767