title: Express a "case ... of" pattern more elegantly in Haskell
body: <p>I came across a pattern which I believe can be expressed more elegantly:</p>
  <p>I have two functions <code>f1,f2 :: Int -&gt; Int</code> (their impl. is not relevant), and a <code>process :: Int -&gt; Int</code> which does the following:</p>
  <ul>
  <li>if <code>f1 x</code> produces <code>x1</code> different from <code>x</code>, then repeat the process with <code>x1</code></li>
  <li>otherwise, if <code>f2 x</code> produces <code>x2</code> different from <code>x</code>, then repeat the process with <code>x2</code></li>
  <li>finally, stop the process and return <code>x</code></li>
  </ul>
  <p>My <code>case ... of</code> implementation is the following:</p>
  <pre class="lang-hs prettyprint-override"><code>f1 :: Int -&gt; Int
  f1 = undefined
  
  f2 :: Int -&gt; Int
  f2 = undefined
  
  process :: Int -&gt; Int
  process x =
      case f1 x of
          x -&gt;
              case f2 x of
                  x -&gt; x
                  x' -&gt; process x'
          x' -&gt; process x'
  </code></pre>
  <p>which produces the following warnings:</p>
  <pre><code>so.hs:13:17: warning: [-Woverlapping-patterns]
      Pattern match is redundant
      In a case alternative: x' -&gt; ...
     |
  13 |                 x' -&gt; process x'
     |                 ^^^^^^^^^^^^^^^^
  
  so.hs:14:9: warning: [-Woverlapping-patterns]
      Pattern match is redundant
      In a case alternative: x' -&gt; ...
     |
  14 |         x' -&gt; process x'
     |         ^^^^^^^^^^^^^^^^
  </code></pre>
  <p>Can anyone shed some light as to what patterns are overlapping, and how to implement <code>process</code> more elegantly?</p>