On Wed, Oct 06, 1999 at 12:04:03 +0200, Sven Panne wrote:
> Michael Weber wrote:
>> marshalListN :: Int -> [a] -> IO Addr
>
> I don't see a reason for the duplication of length information, e.g.
> what should `marshalListN 1000 [1,2,3]' mean? And
> `marshalListN 2 [1,2,3]' is equivalent to `marshalList (take 2 [1,2,3])'.
Yes... I thought about this, but otherwise there would be a `marshalList'
and `marshalListN' with same type signature, which I also regarded as
confusing.
>> where `marshalList' stores the list length at the beginning of the buffer,
>> like: [ marshalList code deleted ]
> This seems to be a rather special case, e.g. why should the length be
> marshaled as an Int? Some ancient Pascals on PCs used a byte length prefix
> for strings. And what about alignment? There could/must be some padding if
> the alignment constraints for the list element type are stronger than the
> ones for Int.
Yes, I know. I cursed on this stupid Pascal string limit in school :-) But
how else can you marshall an arbitrary length list? For Int lists, there is
no zeroElem...
BTW: This is what is done in XDR (eXternal Data Representation standard, see
RFC1832). The length is at the beginning, coded as big-endian 32Bit unsigned
int (we could use `writeInt32OffAddr . ccall_to_htonl' for this...)
> It seems that both spellings are possible and both "feel right", depending
> on the speaker and the dictionary. :-)
That's what I expected... :-)
Cheers,
Michael