[Haskell-cafe] Best way to return Bool based on a successful pattern match?
ab at fmap.me
Mon Jul 13 11:45:12 UTC 2015
Every now and then I'm in a need to check if a value satisfies pattern
with a Bool result. So far I know several ways to do this:
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; _ ->
Usually I go for (1) because I use lens extensively anyway, but for
one-time usage all the extra machinery seems too much. I don't like (2)
when I don't have a library defining that for me, and also (3) -- they
seem inelegant. Is there any syntactic trick that I'm missing that makes
it look nicer?
More information about the Haskell-Cafe