Proposal: Add hasBitSize to Data.Bits.Bits

Ian Lynagh igloo at earth.li
Fri Jul 27 21:42:31 CEST 2012


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

Can you give an example of a situation in which you would use
hasBitSize, and do something useful if it returned False?

Would it be better to move bitSize into a separate class?

> since the vast majority of instances are finite, it may be reasonable to
> set the default definition to
> 
> hasBitSize _ = False

Did you mean True?

Either way, I think I would personally prefer not to have a default, so
that people need to actually check existing instances.


Thanks
Ian




More information about the Libraries mailing list