Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: Does Num class "inherit" Eq class?

Tags:

haskell

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

like image 322
jcarpio Avatar asked Apr 16 '14 17:04

jcarpio


1 Answers

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

like image 62
Lee Avatar answered Oct 04 '22 01:10

Lee