[Haskell-cafe] Best way to return Bool based on a successful pattern match?
haskell at nand.wakku.to
Mon Jul 13 18:10:22 UTC 2015
Concerning monad patterns, I was thinking of expressions like these:
do SomeEvent a <- streamOfEvents
Depending on the stream monad involved (including ), this can have the
On Mon, 13 Jul 2015 21:01:54 +0300, Nikolay Amiantov <ab at fmap.me> wrote:
> 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