<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi,<br><br>I was writing a code trying to use MonadPlus to detect some error cases (representing missing values etc. in pure code). With the Maybe monad, I can do this:<br><br>can0 :: (a -&gt; Maybe b) -&gt; a -&gt; Bool<br>can0 f x = case f x of<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Nothing -&gt; False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Just&nbsp; x -&gt; True<br><br>And I got the expected result:<br><br>*Main&gt; can0 (\x -&gt; Just x) 1<br>True<br><br>But, when I try to generalize this using MonadPlus, as follows:<br><br>can :: (MonadPlus m) =&gt; (a -&gt; m b) -&gt; a -&gt; Bool<br>can f x = case f x of <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mzero -&gt; False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ -&gt; True<br><br><br>I got a warning:<br><br>__testError.hs:31:11:<br>&nbsp;&nbsp;&nbsp; Warning: Pattern match(es) are overlapped<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In a case alternative: _ -&gt; ...<br>Ok, modules loaded: Main.<br><br>And the result is also not as intended (see also can0):<br><br>*Main&gt; can (\x -&gt; Just x) 1<br>False<br><br><br>Can anyone help to explain why this wouldn't work or if there is a workaround to use Monadplus and mzero (or Monad and fail) to achieve this?<br><br><br>Thanks in advance for your help<br><br>Ting<br><br>                                               </div></body>
</html>