Adding binarySize to Binary

Neil Mitchell ndmitchell at
Mon Feb 5 13:37:38 EST 2007


> As it would operate on types rather than values (think sizeOf), the
> result for "[a]" would probably be "(1, Nothing)" - a list takes one
> byte at minimum and infinite bytes at maximum.

That interface seems horrible - it looks like it will only be useful
to a small number of people, and not be general at all. I really don't
like the idea of an interface specifying a "fuzz factor" (which is
what upper/lower bounds correspond to)

In my BinaryDefer library I have a class BinaryDeferStatic:

class BinaryDefer a => BinaryDeferStatic a where
    -- | Must be a constant, must not examine first argument
    getSize :: Proxy a -> Int

This is for things which have a fixed and static size based on their type.

I could also see a reason for having a sizeOf method in the Binary
class - where if unimplemented it just calls encode and then B.length.

Anything else just seems to be an ugly API...



More information about the Libraries mailing list