title: mzero on pattern matching
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3479116/pattern-matching-variables-in-a-case-statement-in-haskell">Pattern matching variables in a case statement in Haskell</a>  </p>
  </blockquote>
  
  
  
  <p>I have the following simplified code (the actual code does implement something meaningful
  ):</p>
  
  <pre><code>import Data.Char
  import Data.Maybe
  import Control.Monad
  import Control.Applicative
  
  testA :: [Int] -&gt; Maybe Int -&gt; Maybe Int
  testA [] _       = Nothing
  testA _  Nothing = Nothing
  testA (x:xs) v = case x of
    1         -&gt; (+) &lt;$&gt; v &lt;*&gt; return x
    otherwise -&gt; testA xs v
  
  testB :: (MonadPlus m, Applicative m) =&gt; [Int] -&gt; m Int -&gt; m Int
  testB [] _     = mzero
  testB _  mzero = mzero
  testB (x:xs) v = case x of
    1         -&gt; (+) &lt;$&gt; v &lt;*&gt; return x
    otherwise -&gt; testB xs v
  
  main = do
    let xpto = testA [1,2,3,1,5] (Just 5)
    print xpto
    let ypto = testB [1,2,3,1,5] (Just 5)
    print ypto
  </code></pre>
  
  <p>It is my understanding that testA and testB should behave the same when feed with the Maybe Monad, meaning that mzero should translate to Nothing.</p>
  
  <p>However, in test B ghc actually gives a warning:</p>
  
  <pre><code>Pattern match(es) are overlapped
  In an equation for `testB': testB (x : xs) v = ..
  </code></pre>
  
  <p>And the output is different:</p>
  
  <pre><code>Just 6 (correct)
  Just 5 (incorrect)
  </code></pre>
  
  <p>I am not sure what I might be missing, why isn't the mzero equivalent to nothing in the pattern match?</p>