title: Could not deduce (Eq a) from the context (...)
body: <p>I'm new to Haskell. I wrote this code:</p>
  
  <pre><code>deleteDuplicates :: [a] -&gt; [a]
  deleteDuplicates [] = []
  deleteDuplicates (x:xs)
          | x == (head xs)        = x : (deleteDuplicates (tail xs))
          | otherwise             = x : (head xs) : (deleteDuplicates (tail xs))
  </code></pre>
  
  <p>What does this error mean and why did it occur? Am I accidentally comparing two different types somehow?</p>
  
  <pre><code>set2.hs:10:3:
      Could not deduce (Eq a) from the context ()
        arising from a use of `==' at set2.hs:10:3-16
      Possible fix:
        add (Eq a) to the context of
          the type signature for `deleteDuplicates'
      In the expression: x == (head xs)
          In a stmt of a pattern guard for
                   the definition of `deleteDuplicates':
            x == (head xs)
      In the definition of `deleteDuplicates':
          deleteDuplicates (x : xs)
                             | x == (head xs) = x : (deleteDuplicates (tail xs))
                             | otherwise = x : (head xs) : (deleteDuplicates (tail xs))
  </code></pre>