binary files in haskell
Manuel M. T. Chakravarty
chak@cse.unsw.edu.au
Wed, 07 Feb 2001 14:06:02 +1100
Simon Marlow <simonmar@microsoft.com> wrote,
> Olaf wrote,
> > Simon Marlow wrote,
> > > 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.
Like in any other language, too. If you are writing binary
data, you get all the problems of writing binary data. I
agree that on top of that it would be nice to have some
really nice serilisation routines, but that should be a
second step.
> Overloading with Storable gives you more flexibility, since if you have
> a way to serialise an object in memory for passing to a foreign
> function, you also have a way to store it in binary format in a file
> (modulo problems with pointers, of course).
Yep, good idea.
Cheers,
Manuel