Proposal: Add hasBitSize to Data.Bits.Bits

Antoine Latter aslatter at
Sun Jul 29 18:37:57 CEST 2012

On Sun, Jul 29, 2012 at 10:37 AM, Thomas Schilling
<nominolo at> wrote:
> On 29 July 2012 15:37, Thomas DuBuisson <thomas.dubuisson at> wrote:
>>> Is 'bitSize' a useful function to use monomorphically? It seems a
>>> waste and irritating to have it return Maybe if I'm not using
>>> Integer.
>> That is a great point.  Most my uses of 'bitSize' are monomorphic and
>> Maybe would just be silly.  OTOH, I'd be more than happy to fix up any
>> polymorphic code to include a new BitSize constraint.
> To make sure I understand this correctly:
> The current problem is that bitSize is a partial function *depending
> on the type* of its argument (currently it always returns _|_ for
> Integer, and is total for any other type). That does indeed seem like
> a Bad Idea.
> You propose to:
>   1. Remove "bitSize" from the Bits class.
>   2. Add a new class BitSize which only contains the "bitSize" method.
> Integer would not be an instance of this class.

The downside to this proposal is that the requester (Edward) actually
wants a function of type "a -> Maybe Int", so his polymorphic function
can handle both infinite bit-types and finite bit-types.

With the new class, Edward could write:

class BitTraversable i where
  traverseBits :: <sometype>

instance (BitSize i) => BitTraversable i where
  traverseBits = <something>

instance BitTraversable Integer where
  traverseBits = <something else>


More information about the Libraries mailing list