Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Tue, 21 Aug 2001 13:54:11 +0100

> Am I right in thinking that there aren't currently any standard
> libraries for converting values to bitstreams and back, to be
> saved in files or squirted over network sockets or whatever to
> be resurrected later or elsewhere?

There is a 'Bits' library supplied with ghc, but it only gives you
word-at-a-time operations, and instances only really make sense for
fixed-size types like Int, Word, Float, Double, etc.

A few years ago I spent a while developing a 'Binary' library which
gives true bit-stream operations, where basically you can serialise
any data structure to an arbitrary-length bit-stream.  This library
is supplied with nhc98, and Sven Panne ported it to ghc.  I also
adopted Noel Winstanley's standalone tool 'DrIFT' for automatically
deriving instances of the Binary class, which answers one of your
other questions.  It is pretty easy to extend DrIFT to derive any
class you might design.

Web references:

   Binary:      ftp://ftp.cs.york.ac.uk/pub/malcolm/ismm98.html
   Binary/GHC:  http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne/haskell_libs/Binary.html
   DrIFT:       http://www.cs.york.ac.uk/fp/DrIFT/