title: Implying equality in a Haskell pattern match
body: <p>I'm writing a function to simplify a Boolean expression. For example, <code>Nand(A, A) == Not(A)</code>. I've tried to implement this particular rule using pattern matching, like so:</p>
  
  <pre class="lang-hs prettyprint-override"><code>-- Operands equivalent - simplify!
  simplify (Nand q q) = Not (simplify q)
  -- Operands must be different, so recurse.
  simplify (Nand q q') = Nand (simplify q) (simplify q')
  </code></pre>
  
  <p>Upon compiling, I get the error:</p>
  
  <pre><code>Conflicting definitions for `q'
  Bound at: boolean.hs:73:21
            boolean:73:29
  In an equation for `simplify'
  </code></pre>
  
  <p>I think I understand what's going on, and I've worked around it, but I'd just like to know:</p>
  
  <ol>
  <li>Why is this sort of pattern matching not possible?</li>
  <li>Is there an idiomatic workaround?</li>
  </ol>
  
  <p><em>Full disclosure: this is related to homework, but the purpose of the course is not to learn Haskell, and I've solved it my own way anyway.</em></p>