So, I have a very simple function that take two parameters : the first is a hour (between 0 and 23) and the second one is a minute (between 0 and 59). This function return the hour plus one minute, and format the hour in a beautiful style. By example, hour 11 12 return 11 heures et 13 minutes. Sorry for the french format of the hour.
So, I use in this function the show function, and the parameters need to be a number, so I have the type declaration (Num a, Show a) => a -> a -> String. But, when I try the function, I got an error and GHC say to me to add the Eq type constraint, but I don't understand why I need the Eq type constraint in this case. There is the code (again, sorry for the french text used in the function, but I think that it's not very important if you don't understand the function name and the text) :
heure :: (Num a, Eq a, Show a) => a -> a -> String
heure 23 59 = "Minuit"
heure 12 m = "Midi et " ++ show (m+1) ++ " minutes"
heure h 59 = show (h+1) ++ " heures"
heure h m = show h ++ " heures et " ++ show (m+1) ++ " minutes"
So : if I don't use Eq, I have an error and when I use it my code is correct. Why?
Thank you for your explanations!
Numof numeric types is a subclass ofEq, since all numbers may be compared for equality." But what's going on here is that recent versions of GHC don't do it: "TheNumclass no longer hasEqorShowsuperclasses. A number of other classes and functions have therefore gained explicitEqorShowconstraints, rather than relying on aNumconstraint to provide them." - Luis Casillas