[Haskell-cafe] Best way to return Bool based on a successful pattern match?

Adam Bergmark adam at bergmark.nl
Mon Jul 13 13:24:40 UTC 2015


Perhaps this is of interest to you,
http://hackage.haskell.org/package/generic-maybe

HTH,
Adam

On Mon, Jul 13, 2015 at 3:04 PM, Nikolay Amiantov <ab at fmap.me> wrote:

> Yes, for standard data types like Either or Maybe the best way is to use
> library-defined functions -- I was more interested in a way to check for
> any given pattern, which would look nicer than a custom defined function
> or a LambdaCase. An example use case:
>
> partition (\case MyPat -> True; _ -> False)
>
> Anyway using lens for this is already very readable and concise, albeit
> needs makePrisms/Lens and stuff.
>
> On 07/13/2015 03:02 PM, Nikita Karetnikov wrote:
> > Looking at the instances defined for Bool and Either, I don't think
> > there's a higher level way of doing it.  But even if there's one, it'll
> > probably be more obscure than isLeft, which is in base since 4.7.0.0.
> >
>
> --
> Nikolay.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150713/7780b7fe/attachment.html>


More information about the Haskell-Cafe mailing list