title: Why is this type variable ambiguous?
body: <p>Cabbage.hs:</p>
  
  <pre><code>module Cabbage where 
  class Cabbage a
    where foo :: a -&gt; String      -- the parameter is only present for its type,
                                  -- the parameter value will be ignored
          bar :: String -&gt; a
  quux :: Cabbage a =&gt; String -&gt; a
  quux s = bar (s ++ foo (undefined :: a))
  </code></pre>
  
  <p>When I compile (with ghc) I get this error message:</p>
  
  <pre><code>Cabbage.hs:7:19:
      Ambiguous type variable `a' in the constraint:
        `Cabbage a' arising from a use of `foo' at Cabbage.hs:7:19-38
      Probable fix: add a type signature that fixes these type variable(s)
  </code></pre>
  
  <p>I don't understand why <code>a</code> is ambiguous.  Surely the <code>a</code> in line 7 is the same as the <code>a</code> in line 6?  How do I fix this?</p>
  
  <p>Alternatively, is there a better way of declaring a per-instance constant?</p>