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

Sven Panne svenpanne at gmail.com
Mon Jul 13 16:49:25 UTC 2015

2015-07-13 13:45 GMT+02:00 Nikolay Amiantov <ab at fmap.me>:

> [...]
> 1. Use lens: `has _Left`
> 2. Make a function: `isLeft (Left _) = True; isLeft _ = False`
> 3. (When you need a lambda) Use LambdaCase: `\case Left _ -> True; _ ->
> False`
> [...]

http://www.extremeprogramming.org/rules/simple.html ;-) So IMHO a simple,
old-skool '\x -> case x of Left _ -> True; _ -> False' (probably item 2.5
in the list above) is by far the "best" way: It doesn't use any kind of
extension, it doesn't pull in a dozen of packages for a trivial task, and
is readable by anyone. My personal experience is that things which look
very clever and advanced (like using meta/reflection facilities) only
increase the WTF factor in the long run. Those facilities have their uses,
but they come with a heavy cost which must be justified somehow. Boring
code is good code! :-D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150713/a9f63f4c/attachment.html>

More information about the Haskell-Cafe mailing list