Reading/Writing Binary Data in Haskell

Simon Peyton-Jones
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
( Most recently George Russell posted a library,
but I don't know it's portability

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
but presumably much of the infrastructure for both purposes would be the

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


| -----Original Message-----
| From: [] On
Behalf Of Wolfgang Jeltsch
| Sent: 09 July 2003 09:21
| To: The Haskell Mailing List
| Subject: Re: Reading/Writing Binary Data in Haskell
| On Wednesday, 2003-07-09, 05:31, Glynn Clements wrote:
| > [...]
| > There isn't a standard mechanism for binary I/O.
| 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?
| > 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.
| This will most likely cause problems under Windows. The reason is that
| standard I/O functions are intended for reading and writing text, and
| 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.
| > 2. Use "map (fromIntegral . ord) ..." to get a list of "Word8"s
| 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
| > [...]
| Wolfgang
| _______________________________________________
| Haskell mailing list