I just wrote the following two functions:
fand :: (a -> Bool) -> (a -> Bool) -> a -> Bool
fand f1 f2 x = (f1 x) && (f2 x)
f_or :: (a -> Bool) -> (a -> Bool) -> a -> Bool
f_or f1 f2 x = (f1 x) || (f2 x)
They might be used to combined the values of two boolean functions such as:
import Text.ParserCombinators.Parsec
import Data.Char
nameChar = satisfy (isLetter `f_or` isDigit)
After looking at these two functions, I came to the realization that they are very useful. so much so that I now suspect that they are either included in the standard library, or more likely that there is a clean way to do this using existing functions.
What was the "right" way to do this?
One simplification,
or
in the
((->) r)
applicative functor.Applicative version
Why? We have:
So:
Monad version
Or for
liftM2
, we have:so: