[Haskell-cafe] Why is Bool no instance of Num and Bits?

Stephan Friedrichs deduktionstheorem at web.de
Sat May 9 02:30:14 EDT 2009


Neil Mitchell wrote:
> 
> [...]
> 
> Which is a shame, having Bits on Bool seems entirely logical, having
> Num a superclass of Bits seems a little less clear.
> 

There are two default implementations in Bits

    bit i         = 1 `shiftL` i
    x `testBit` i = (x .&. bit i) /= 0

which rely on Num (and on the fact that 0 ~= 0..0 and 1 ~= 0..01, which
doesn't have to be the case in all Num instances?). But is that worth
having Num as superclass? When declaring in instance for Bits you have
to implement at least 8 functions anyway so these two IMHO don't really
make a difference, do they?

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr


More information about the Haskell-Cafe mailing list