<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 -> Maybe b) -> a -> Bool<br>can0 f x = case f x of<br> Nothing -> False<br> Just x -> True<br><br>And I got the expected result:<br><br>*Main> can0 (\x -> Just x) 1<br>True<br><br>But, when I try to generalize this using MonadPlus, as follows:<br><br>can :: (MonadPlus m) => (a -> m b) -> a -> Bool<br>can f x = case f x of <br> mzero -> False<br> _ -> True<br><br><br>I got a warning:<br><br>__testError.hs:31:11:<br> Warning: Pattern match(es) are overlapped<br> In a case alternative: _ -> ...<br>Ok, modules loaded: Main.<br><br>And the result is also not as intended (see also can0):<br><br>*Main> can (\x -> 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>