NOTE: there seems to be an error in GHC> = 7 , which makes the GHC class methods acceptable even in Haskell 98 mode.
In addition, the example from the manual is always taken when you enable MultiParamTypeClasses , regardless of whether the ConstrainedMethodTypes extension is enabled (also a likely error).
In type elem :
elem :: Eq a => a -> sa -> Bool
a and s are class type variables, and Eq a is a restriction on a class type variable a . As the manual says, Haskell 98 prohibits such restrictions (FWIW, it also prohibits classes with multiple parameters). Therefore, the following code should not be accepted in Haskell 98 mode (and I think that it is also forbidden in Haskell 2010):
class Compare a where comp :: Eq a => a -> a -> Bool
And indeed, GHC 6.12.1 rejects it:
Prelude> :load Test.hs [1 of 1] Compiling Main ( Test.hs, interpreted ) Test.hs:3:0: All of the type variables in the constraint `Eq a' are already in scope (at least one must be universally quantified here) (Use -XFlexibleContexts to lift this restriction) When checking the class method: comp :: (Eq a) => a -> a -> Bool In the class declaration for `Compare' Failed, modules loaded: none. Prelude> :set -XConstrainedClassMethods Prelude> :load Test.hs [1 of 1] Compiling Main ( Test.hs, interpreted ) Ok, modules loaded: Main.
The idea is that you should use superclass restrictions instead:
class (Eq a) => Compare a where comp :: a -> a -> Bool
Regarding semantics, you can easily check if a class method constraint is not limited to adding a superclass constraint with the following code:
{-
Testing with GHC 6.12.1:
*Main> :load Test.hs [1 of 1] Compiling Main ( Test.hs, interpreted ) Ok, modules loaded: Main. *Main> comp A <interactive>:1:0: No instance for (Eq A) arising from a use of `comp' at <interactive>:1:0-5 Possible fix: add an instance declaration for (Eq A) In the expression: comp A In the definition of `it': it = comp A *Main> someMethod AA A *Main> comp BB True
Answer: no, it is not. The restriction applies only to a method with a limited type. So you are right, this is opportunity number 2.