When I enter :t 4 in ghci I get
Prelude> :t 4
4 :: Num t => t
I understand why 4 is not only an Int or an Integer and that it is infered bottom up but I do not understand why 4 is not shown as an Ord t => t or even more correct something like this:
4 :: (Ord t || Num t) => t
Because 4 is both an Ord and a Num but Ord and Num have no connection...
So why does :t 4 output only Num?
Not all types with instances for Num also have instances for Ord, and you only need the fromInteger part of Num to have the overloaded numeric literals Haskell has. For example, Complex from Data.Complex has a Num instance but no Ord. In this case, 4 is not an Ord.
ghci> import Data.Complex
ghci> let x = 1 :: Complex Double
ghci> let y = 2 :: Complex Double
ghci> x < y
<interactive>
* No instance for (Ord (complex Double)) arising from use of `<'
* In the expression: x < y
In the equation for `it': it = x < y
ghci>
As @Lee commented, this is the behavior outlined in the report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With