Proposal: Remove Num superclass of Bits

Isaac Dupree ml at isaac.cedarswampstudios.org
Sun Oct 16 07:45:28 CEST 2011


On 10/15/2011 06:56 AM, Roman Leshchinskiy wrote:
> On 15/10/2011, at 11:11, Ian Lynagh wrote:
>
>> On Sat, Oct 15, 2011 at 11:56:27AM +0200, Bas van Dijk wrote:
>>> On 15 October 2011 00:01, Ian Lynagh<igloo at earth.li>  wrote:
>>>> Removing the Num superclass of Bits was also mentioned, but that would
>>>> need its own proposal.
>>>
>>> Ok, I would like to propose removing the Num superclass of Bits.
>>
>> Would we just remove default methods like
>>     bit i = 1 `shiftL` i
>>     x `testBit` i = (x .&. bit i) /= 0
>> ?
>
> The Num superclass is only needed to be able to say 0 and 1. Perhaps we should just add the methods zero and one to Bits?

As others observed, "one" is only useful for the "bit" method default, 
and might be meaningless for an "instance () Bits" (whereas the rest of 
the class makes sense for () as a zero-bit instance, albeit a use 
doesn't come to mind).  Or, similarly to (), a bit-vector which contains 
its length statically in its type: it would be simpler if length zero 
was just as valid as any other length.  And it would be a bit strange to 
define 'one' as a value equal to 'zero'.

But proposed member 'zero' is plain and simply "all bits zero".  I can 
imagine users of Bits using that method, too.

(Side note: are there other classes that want to call things zero? e.g. 
there is mzero in MonadPlus.  Bits is designed to import unqualified 
easily. Hoogle doesn't find anything currently named 'zero', so it may 
be fine.)

(Horrible side note: 'bit' could default to
bit i = one `shiftL` i
         where one = complement ((complement zero) `shiftL` 1)
[/end experienced-C-bit-twiddler confession]
)

~Isaac



More information about the Libraries mailing list