Nothing forbids you from allowing negative bit positions in a data type, for instance for fractional bits in a fixed position numeric type.

Consequently, I'm -1 on this proposal.

You can currently construct 0 several ways, e.g. clearBit (bit 0) 0 could be use to supply a default for any such zeroBits member of the class.

-Edward


On Sun, Feb 16, 2014 at 5:14 AM, Herbert Valerio Riedel <hvr@gnu.org> wrote:
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)"[1] seems to result in just such a zero-value for all
'Bits' instances from base, so I'd hereby propose to simply document
this as an expected property of 'bit', as well as the recommended way to
introduce a zero-value (for when 'Num' is not available).

Discussion period: 2 weeks

 [1]: ...or more generally 'bit n == 0' for n<0, as it's usually
      implemented as 'bit n = 1 shift n'
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://www.haskell.org/mailman/listinfo/libraries