getting a Binary module into the standard libs

Simon Marlow simonmar@microsoft.com
Tue, 12 Nov 2002 10:24:13 -0000


> Mon, 11 Nov 2002 10:12:57 -0800 (PST), Hal Daume III=20
> <hdaume@ISI.EDU> pisze:
>=20
> >>   putBits :: BinHandle -> Int{-size-} -> Int{-value-} -> IO ()
>=20
> > Any reason not to make those Word8s instead of Ints?
>=20
> Any reason to limit value to 8?
>=20
> I've heard: endianness, but if we fiddle with parts smaller=20
> than a byte
> we already chose endianness when decided whether to fill=20
> bytes starting
> from the low or high bit! Starting from low bit implies LE, starting
> from high bit implies BE - anything else is inconsistent.

Well, we have to choose an arbitrary endianness for multibyte integers
already - it doesn't matter which one we choose, as long as it is
consistent.

I suggested restricting putBits to a maximum of 8 bits because it's easy
to implement and a good compromise.  Once you have putBits up to size 8,
you can implement everything else: the library is already implemented in
terms of putByte/getByte, so the only further change is to use putBits
instead of putByte for small numbers such as constructor tags.

We could allow putBits to work up to size 32, which would mean our
instances of Binary for the other integral types will be simpler, but
the complexity is moved into putBits.  It's not a big deal.  I suppose
this way you'd get to take advantage of 23 bit numbers, but that's not
going to buy very much.

> For the bit count - they are generally expressed as Ints, as anything
> which is guaranteed to be quite small. Word8 for bit count is quite
> arbitrary and increases explicit conversions which need to be made -
> Int is more common than Word8.

Agreed.=20

Cheers,
	Simon