title: Semantics for GHC extension allowing constraints on methods (-XConstrainedClassMethods)
body: <p>The following is quoted from the GHC user guide (Haskell Platform 2012.4.0.0)...</p>
  
  <blockquote>
    <h3>7.6.1.3. Class method types</h3>
    
    <p>Haskell 98 prohibits class method types to mention constraints on the class type variable, thus:</p>
  
  <pre><code>class Seq s a where
    fromList :: [a] -&gt; s a
    elem     :: Eq a =&gt; a -&gt; s a -&gt; Bool
  </code></pre>
    
    <p>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).</p>
  </blockquote>
  
  <p>However, I don't see any explanation of what this means. I can see two possibilities...</p>
  
  <ol>
  <li>The <code>Seq</code> type class implicitly gains the <code>Eq a</code> constraint from <code>elem</code>.</li>
  <li>The <code>elem</code> method cannot be used for type class <code>Seq</code> in cases where <code>a</code> is not a member of class <code>Eq</code> (or where it is a member, but that's unknown where <code>elem</code> is used).</li>
  </ol>
  
  <p>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.</p>
  
  <p>The example seems to motivate exactly this - the idea being that <code>elem</code> is often a useful operation for sequences, too valuable to live without, yet we also want to support those sequences where <code>elem</code> is unsupportable, such as sequences of functions.</p>
  
  <p>Am I right, or have I missed something? What are the semantics for this extension?</p>