The following is quoted from the GHC user guide (Haskell Platform 2012.4.0.0)...
7.6.1.3. Class method types
Haskell 98 prohibits class method types to mention constraints on the class type variable, thus:
class Seq s a where fromList :: [a] -> s a elem :: Eq a => a -> s a -> Bool
The type of elem is illegal in Haskell 98, because it contains the constraint Eq a, constrains only the class type variable (in this case a). GHC lifts this restriction (flag -XConstrainedClassMethods).
However, I don't see any explanation of what this means. I can see two possibilities...
- The
Seq
type class implicitly gains theEq a
constraint fromelem
. - The
elem
method cannot be used for type classSeq
in cases wherea
is not a member of classEq
(or where it is a member, but that's unknown whereelem
is used).
I strongly suspect (2) because it seems potentially useful whereas (1) seems useless. (2) basically allows methods to be defined for cases where they can be supported, without limiting the typeclass to only being instanced for those cases.
The example seems to motivate exactly this - the idea being that elem
is often a useful operation for sequences, too valuable to live without, yet we also want to support those sequences where elem
is unsupportable, such as sequences of functions.
Am I right, or have I missed something? What are the semantics for this extension?
-XHaskell98
enabled. I filed a ticket. – Mikhail Glushenkov