From Learn You a Haskell, I have:
lucky :: Integral a => a -> String
lucky 7 = "lucky number seven!"
lucky x = "try again"
but, when I do
lucky :: Num a => a -> String
lucky 7 = "lucky number seven!"
lucky x = "try again"
I get
Could not deduce (Eq a) arising from literal `7'
So, then I do
lucky :: (Eq a, Num a) => a -> String
lucky 7 = "lucky number seven!"
lucky x = "try again"
and, the compiler is happy.
Doesn't the Num type class "inherit" the Eq class?
Saying (Num a, Eq a) seems redundant. From the Haskell 98 report, where they have a great diagram (yeah, visuals!) of the Standard Classes it sure seems like it's "inherited." http://www.haskell.org/onlinereport/basic.html
The Haskell report suggests that Num
should be a subclass of Eq
and Show
, but if you look at the source for the Num
class in ghc, then it is not.
This change appears to have been introduced in GHC 7.4.1
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