You get this error message because both 1
and +
are polymorphic--they can both work for different types!
Take a look:
Prelude> :t 1
1 :: Num a => a
Prelude> :t (+)
(+) :: Num a => a -> a -> a
So both 1
and +
are meaningful for any type in the Num
class. So when you write 1 + Bool
, the 1
could actually be a Bool
, if Bool
had a Num
instance. In fact, you can do that yourself:
instance Num Bool where
fromInteger x = x /= 0
(+) = (&&)
...
Once you do this, 1 + True
will actually work. You will also be able to use numeric literals as bools:
*Main> 1 :: Bool
True
*Main> 1 + True
True
This also explains why you get the same error regardless of the order of arguments: the only actual problem in your code is the True
--if that worked, everything else would too.