Proposal: Explicitly require "Data.Bits.bit (-1) == 0" property

Henning Thielemann schlepptop at
Sun Feb 16 12:17:40 UTC 2014

Am 16.02.2014 11:14, schrieb Herbert Valerio Riedel:
> Hello *,
> Right now, there seems to be no "defined" way to create a zero
> 'Bits'-value (w/o requiring also a 'Num' instance), that has all bits
> cleared without involving at least two operations from the 'Bits' class
> (e.g. `clearBit (bit 0) 0` or `let x = bit 0 in xor x x`).
> OTOH, introducing a new method 'class Bits a where bitZero :: a' seems
> overkill to me.
> However, "bit (-1)"

It would be better to forbid "bit (-1)" by the type system, if this 
would be possible. If only indices would be allowed that actually exist, 
then we would have a nice law like "popCount (bit n) == 1". I would not 
like that the exceptional "bit (-1)" becomes the blessed way to create 
zeros. An additional "zero" method with a default implementation would 
be the clean way.

More information about the Libraries mailing list