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

Neil Mitchell ndmitchell at gmail.com
Fri May 8 12:04:54 EDT 2009


> Does that also mean that you could write:
>
> if 3 - 4 then ... else ...  (= if (fromInteger 3 :: Bool) - (fromInteger 4
> :: Bool) then ... else ...)

No. 3 - 4 is an Integer, the proposal is to convert Bools to Ints, not
Ints to Bools. Of course, Lennart has been asking for precisely this
functionality (overloaded Booleans) for some time - so one day it may
be possible!

You could however do:

if 3 then ... else ..

> If you change fromInteger in Num Bool to be fromInteger x = x /= 0, then we
> could all start writing nasty C-like if-expressions...

Yeah, the more people give examples of the power of Num Bool, the more
it seems like a very bad idea!

Which is a shame, having Bits on Bool seems entirely logical, having
Num a superclass of Bits seems a little less clear.

Thanks

Neil


More information about the Haskell-Cafe mailing list