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

Nikolay Amiantov ab at fmap.me
Mon Jul 13 18:01:54 UTC 2015

Ouch, I feel deeply ashamed for not thinking of that from the beginning!
While not being a general solution "Pattern a -> a -> Bool" this covers
almost all my use cases (with rest of processing, too) while requiring
no extensions, no dependencies and overall being readable and "boring"
in Sven's sense (at least I feel so -- comprehensions are being taught
in every Haskell tutorial under the sun and are pretty self-describing).
It remains a question of whether it's equally readable in monadic case
("huh? list comprehension? but... this is a Maybe/an Event!"), but in
most my GUI/event-processing code I use lens anyway to cope with deep
hierarchies of records describing events, so it's not much of a problem
there. Thanks!

On 07/13/2015 08:03 PM, Niklas Haas wrote:
> For this specific use case, you can also consider list comprehensions:
> [ x | x@(DataDefinition _) <- tlds ]
> I personally greatly prefer this over something like ‘filter’ + an ugly
> lambda, especially if you can use the list comprehension for the rest of
> your processing as well.

More information about the Haskell-Cafe mailing list