[Haskell-cafe] combining predicates, noob question
Felipe Almeida Lessa
felipe.lessa at gmail.com
Fri Jul 6 20:17:54 CEST 2012
On Fri, Jul 6, 2012 at 2:11 PM, Sebastián Krynski <skrynski at gmail.com> wrote:
> As I was using predicates (a -> bool) , it appeared the need for combining
> them with a boolean operator (bool -> bool -> bool) in order to get a new
> predicate
> combining the previous two. So I wrote my function combinerPred (see code
> below). While I think this is JUST ok, i'm feeling a monad in the air.
> So.. where is the monad?
>
> combinerPred :: (a -> Bool) -> (a -> Bool) -> (Bool -> Bool -> Bool) ->
> (a -> Bool)
> combinerPred pred1 pred2 op = \x -> op (pred1 x) (pred2 x)
That's the `(->) a` monad:
import Control.Applicative
combinerPred :: (a -> Bool) -> (a -> Bool) -> (Bool -> Bool ->
Bool) -> (a -> Bool)
combinerPred pred1 pred2 op = op <$> pred1 <*> pred2
Cheers,
--
Felipe.
More information about the Haskell-Cafe
mailing list