title: Could not deduce (Ord a0) arising from a use of ‘>’
body: <p>I am getting compile-time errors related to typeclasses that I'm trying to create.</p>
  
  <p>My program:</p>
  
  <pre><code>main = print "here"
  
  
  class Tiger a where
    tigerWeight :: (Ord o) =&gt; a -&gt; o
  
  class Zoo a where
    tiger :: (Tiger t) =&gt; a -&gt; t
    tigerHeavier :: a -&gt; a -&gt; Bool
    tigerHeavier x y =
      (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
  </code></pre>
  
  <p>gives compile errors:</p>
  
  <pre><code>$ ghc zoo
  [1 of 1] Compiling Main             ( zoo.hs, zoo.o )
  
  zoo.hs:14:5: error:
      • Could not deduce (Ord a0) arising from a use of ‘&gt;’
        from the context: Zoo a
          bound by the class declaration for ‘Zoo’ at zoo.hs:(10,1)-(14,53)
        The type variable ‘a0’ is ambiguous
        These potential instances exist:
          instance Ord Ordering -- Defined in ‘GHC.Classes’
          instance Ord Integer
            -- Defined in ‘integer-gmp-1.0.0.1:GHC.Integer.Type’
          instance Ord a =&gt; Ord (Maybe a) -- Defined in ‘GHC.Base’
          ...plus 22 others
          ...plus two instances involving out-of-scope types
          (use -fprint-potential-instances to see them all)
      • In the expression:
          (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
        In an equation for ‘tigerHeavier’:
            tigerHeavier x y
              = (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
  
  zoo.hs:14:6: error:
      • Could not deduce (Tiger a1) arising from a use of ‘tigerWeight’
        from the context: Zoo a
          bound by the class declaration for ‘Zoo’ at zoo.hs:(10,1)-(14,53)
        The type variable ‘a1’ is ambiguous
      • In the first argument of ‘(&gt;)’, namely ‘(tigerWeight (tiger x))’
        In the expression:
          (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
        In an equation for ‘tigerHeavier’:
            tigerHeavier x y
              = (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
  
  zoo.hs:14:32: error:
      • Could not deduce (Tiger a2) arising from a use of ‘tigerWeight’
        from the context: Zoo a
          bound by the class declaration for ‘Zoo’ at zoo.hs:(10,1)-(14,53)
        The type variable ‘a2’ is ambiguous
      • In the second argument of ‘(&gt;)’, namely ‘(tigerWeight (tiger y))’
        In the expression:
          (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
        In an equation for ‘tigerHeavier’:
            tigerHeavier x y
              = (tigerWeight (tiger x)) &gt; (tigerWeight (tiger y))
  </code></pre>
  
  <p>Why is this? It seems that all the types should be deducible. In particular:</p>
  
  <ul>
  <li><p>'x' and 'y' are in the Zoo typeclass, and therefore should support the 'tiger' method.</p></li>
  <li><p>(tiger x) is in the 'Tiger' typeclass, as marked by the 'tiger' method's signature.</p></li>
  <li><p>(tigerWeight (tiger x)) therefore should be able to be applied, and is known to be a member of the 'Ord' class, as marked by the 'tigerWeight' method's signature.</p></li>
  </ul>