Transmitting Haskell values

Glynn Clements glynn.clements at virgin.net
Thu Oct 30 03:31:16 EST 2003


Joachim Durchholz wrote:

> > The problem with Storable is that the representation is
> > architecture-specific. It isn't suitable for implementing a
> > "commodity" protocol which can be used for communication between
> > different architectures.
> 
> Just endianness issues, or are there deeper differences?

There could also be differences in the sizes of integral types
(particularly CLong) or other format differences (e.g. use of
something other than IEEE 754 format for FP types).

> If it's just endianness, it should be relatively easy to get that sorted 
> out, either via wrappers around the networking functions, or by 
> extending Storable itself (well, it's probably a bit too early for me to 
> try this, but there's a good chance that it will be at least one of 
> generally useful and instructive *g*).

The problem there is that you can't write a generic function which
handles any instance of Storable. Each specific type would have to be
handled separately, depending upon whether swapping is required and,
if so, whether bytes are swapped in blocks of 2, 4, or 8 bytes. Also a
32-bit float might use a different byte order to a 32-bit int (so says
a comment in glibc's <endian.h>).

-- 
Glynn Clements <glynn.clements at virgin.net>


More information about the Glasgow-haskell-users mailing list