"Steve" == Steve Roggenkamp <[EMAIL PROTECTED]> writes:
Steve> I would like to use Haskell for several larger scale
Steve> projects, but I can't figure out how to read and write
Steve> binary data. It does not appear that the language supports
Steve> binary files. Am I missing something?
"Tim" == Timothy Robin BARBOUR <[EMAIL PROTECTED]> writes:
Tim> There is the (automatically deriveable) Binary class, defined in the
Tim> Haskell Report ? Unfortuately ghc does not support it yet. But ghc
Tim> does provide the Native class (not automatically deriveable), but with
Tim> many pre-defined instances.
The Haskell Report no longer defines a Binary class. However, the
nhc13 compiler now supports an improved library for the Binary class,
including automatic derivation for any user-defined type.
Tim> Another thing you will need is some way to transport your binary data
Tim> between platforms e.g. Intel -> Alpha.
Nhc13's implementation of Binary values always stores the same representation,
regardless of the endian-ness of the underlying machine.
Tim> There have been claims that Read is sometimes very inefficient at
Tim> parsing large structures
Indeed. The Binary class does not suffer from this problem.
Tim> There is another way one might proceed. Why not just use a
Tim> memory-mapped file (mmap) to make the data persistent in-place ?
With our current design, it is possible to map binary files into memory
and vice versa, in a completely orthogonal fashion.
Tim> The data structure better not contain any lazy closures,...
Yes, the three restrictions on our design are:
(1) values must be fully-evaluated when written to a binary file;
(2) sharing is lost, so cycles and infinite structures are excluded;
(3) functions cannot yet be stored in binary files.
Full information on nhc13, including downloads, is available at
http://www.cs.york.ac.uk/fp/nhc13/
This "York" version of nhc13 is currently in beta-release, with a full
public release expected soon. A paper describing a preliminary design
for Binary I/O was published in the Haskell Workshop '97 (and is available
from my homepage). The current design has moved on quite a bit however -
some documentation is available in html, and a new paper is in preparation.
Regards,
Malcolm
[EMAIL PROTECTED]
Dr Malcolm Wallace (functional programming research) +44 1904 434756
Department of Computer Science, University of York, YORK YO1 5DD, U.K.
------------------------------------http://www.cs.york.ac.uk/~malcolm/