[Haskell-cafe] Data.Binary and little endian encoding

Sven Panne Sven.Panne at aedion.de
Mon May 18 12:48:48 EDT 2009


Am Sonntag, 17. Mai 2009 15:08:29 schrieb Don Stewart:
> Sven.Panne:
> > [...]
> > I think most problems can be fixed in a rather pragmatic way by adding a
> > few functions to the binary package:
> [...]
> Patches are welcome.

Attached. A few remarks:

 * This is only a quick and mildly tested implementation of the IEEE 
functions, especially NaNs, infinities and denormalized numbers are untested. 
These problems could totally be avoided if we can coerce representations 
directly, changing only their interpretation.

 * The *host functions assume an IEEE platform, but this can easily be changed 
(see comments).

 * Perhaps one can use unsafeCoerce for word32ToFloat and friends, but I 
haven't checked this.

 * I've seen a few "{- INLINE -}" comments. Is this really wanted or only a 
typo?

 * A comment about using peek/poke for the *le/*be functions is wrong, because 
this would introduce alignment constraints on some platforms.

I think the main point is to provide a nice and efficient API, hiding all the 
dirty stuff in the implementation.

> > One final remarks: I think the low level functions of the binary package
> > should really keep the notions of "endianess" and "alignment constraints"
> > separate, something which isn't done currently: The *host functions have
> > alignment restrictions, the *be/*le functions don't. There is no good
> > reason for this non-orthogonality.
>
> That seems reasonable.

There are various ways to achieve this, but the most obvious way leads to a 
combinatorial explosion of functions:

   <no. of types> * 3 (LE/BE/host) * 2 (aligned/unaligned)

Furthermore, it would be good to split the binary package into the 2 layers 
already discussed first, then it is perhaps a bit clearer what a nice API 
would look like. I think it would be best to shift this API design discussion 
to the libraries list.

Cheers,
   S.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ieee.patch
Type: text/x-patch
Size: 11053 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090518/2a4783ca/ieee.bin


More information about the Haskell-Cafe mailing list