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

Neil Brown nccb2 at kent.ac.uk
Fri May 8 12:00:17 EDT 2009


Neil Mitchell wrote:
> I didn't at first, then I remembered:
>
> 1 + True
> =
> fromInteger 1 + True
>
> And if we have Num for Bool, it type checks.
>   
Does that also mean that you could write:

if 3 - 4 then ... else ...  (= if (fromInteger 3 :: Bool) - (fromInteger 
4 :: Bool) then ... else ...)

or perhaps (not sure if type defaulting stretches to this):

if 1 then ... else ...  (= if (fromInteger 1 :: Bool) 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...

Thanks,

Neil.




More information about the Haskell-Cafe mailing list