[Haskell-cafe] Is there a generic way to detect "mzero"?

Harry Terkelsen het32 at cornell.edu
Mon Mar 26 21:46:11 CEST 2012


Jeff,

I don't think your code works in general, since it is not guaranteed that
x' == mzero is allowed unless (m b) is an instance of Eq. I'm unsure if you
are able to test for mzero in general.

Harry

On Mon, Mar 26, 2012 at 3:11 PM, Jeff Shaw <shawjef3 at msu.edu> wrote:

>
>  can :: (MonadPlus m) => (a -> m b) -> a -> Bool
>> can f x = case f x of
>>            mzero -> False
>>            _ -> True
>>
>>
>> I got a warning:
>>
>> __testError.hs:31:11:
>>    Warning: Pattern match(es) are overlapped
>>             In a case alternative: _ -> ...
>> Ok, modules loaded: Main.
>>
> The problem here is that when you match on "f x", your first match is an
> identifier that matches anything at all, and binds it to mzero. I think
> what you're looking for is
>
>
> can f x = case f x of
>    x' | x' == mzero -> False
>    _ -> True
>
> Jeff
>
> ______________________________**_________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120326/ad163dc6/attachment.htm>


More information about the Haskell-Cafe mailing list