Proposal: Add hasBitSize to Data.Bits.Bits

John Lato jwlato at gmail.com
Sat Jul 28 16:40:36 CEST 2012


> From: Edward Kmett <ekmett at gmail.com>
>
> On Fri, Jul 27, 2012 at 3:42 PM, Ian Lynagh <igloo at earth.li> wrote:
>
>> On Fri, Jul 27, 2012 at 03:06:04PM -0400, Edward Kmett wrote:
>> > There is currently no way to know whether or not calling
>> > Data.Bits.bitSizewill crash your program.
>> >
>> > I propose extending the Bits class to include:
>> >
>> > hasBitSize :: Bits b => b -> Bool
>> >
>> > such that it returns False for Integer and True for the other instances
>
> Would it be better to move bitSize into a separate class?
>
>
> I don't think so. Ultimately, you should be able to know for every numeric
> type if it has a fixed or variable number of bits. In a perfect world 'd
> rather just have bitSize return a Maybe that way we don't have to truck
> with partial functions in the API.
>
> However, the case for just adding hasBitSize is that it avoids breaking
> existing code.

Given that existing code using bitSize can already cause a crash when
used with Integer or other infinite types, wouldn't it be better to
break existing code so authors can fix (or at least examine) their use
of bitSize?

I'm in favor of changing the type of bitSize, although since none of
my code uses that function it's an easy position for me to take.

John L.



More information about the Libraries mailing list