Reading/Writing Binary Data in Haskell

Simon Peyton-Jones simonpj@microsoft.com
Wed, 9 Jul 2003 09:57:55 +0100


A library for reading and writing binary data, portable across both
implementations and platforms, has been a long-standing lack.  It comes
up regularly, and has been discussed recently on the libraries list
(libraries@haskell.org). Most recently George Russell posted a library,
but I don't know it's portability
	http://haskell.org/pipermail/libraries/2003-June/001227.html

There seem to be two slightly different issues:
	a) writing Haskell data structures to a file, so they can be
recovered (exact binary structure
		of the file is irrelevant)
	b) reading and writing files whose exact binary structure is
specified
but presumably much of the infrastructure for both purposes would be the
same.

The way stands open for someone to take up the challenge: define an
interface, agree it with the community, and build an implementation that
works.   Maybe someone is doing this already?  Perhaps George's library
is intended to be such a thing?=20

Anyway, it would be a great service. =20

Simon


| -----Original Message-----
| From: haskell-admin@haskell.org [mailto:haskell-admin@haskell.org] On
Behalf Of Wolfgang Jeltsch
| Sent: 09 July 2003 09:21
| To: The Haskell Mailing List
| Subject: Re: Reading/Writing Binary Data in Haskell
|=20
| On Wednesday, 2003-07-09, 05:31, Glynn Clements wrote:
| > [...]
|=20
| > There isn't a standard mechanism for binary I/O.
|=20
| NHC98 contains the York Binary library. Can someone tell me if this is
| available for other Haskell systems? And didn't GHC also provide
binary I/O?
|=20
| > However, a simple and fairly generic mechanism for doing this is:
| >
| > 1. Read in a list of "Char"s with the standard I/O functions.
|=20
| This will most likely cause problems under Windows. The reason is that
the
| standard I/O functions are intended for reading and writing text, and
that's
| why under Windows the sequence CRLF (#0D#0A) is interpreted as a
single LF
| (#0A) and EOF (#1A) is interpreted as the end of the file.
|=20
| > 2. Use "map (fromIntegral . ord) ..." to get a list of "Word8"s
(octets).
|=20
| This assumes that the standard I/O functions use a one byte character
| encoding. I don't now whether this is guaranteed by the Haskell
report.
|=20
| > [...]
|=20
| Wolfgang
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell