[Haskell-cafe] bitSize

Steve Schafer steve at fenestra.com
Sat Aug 27 19:06:41 CEST 2011

On Sat, 27 Aug 2011 11:57:57 +0100, you wrote:

>I meant if you're trying to *implement* serialisation. The Bits class 
>allows you to access bits one by one, but surely you'd want some way to 
>know how many bits you need to keep?

For fixed-size types (e.g., Int), I might use a simple byte-for-byte
serialization. But these days, I tend to avoid binary serializations,
and use string conversions for all types, taking advantage of whatever
built-in conversions the language offers. There's obviously more
overhead, but the advantages usually outweigh the disadvantages. For one
thing, I can come back a couple of years later and still figure out what
the data are supposed to be.

>Likewise, you say the standard PRNG can be used to generate random 
>Integers, but what if you're trying to implement a new PRNG?

I'm not aware of of any PRNGs that use variable-length types (and I
would think that such a PRNG wouldn't be very efficient), so I'm still
not sure that I understand the question.

-Steve Schafer

More information about the Haskell-Cafe mailing list