You can still use the monadic combinators, with the price of wrapping and unwrapping in case of newtype. <br><br>newtype P a = P {unP :: a -> Bool}<br>liftM2'P :: (Bool -> Bool -> Bool) -> P a -> P a -> P a<br>
liftM2'P op = (P .) . on (liftM2 op) unP<br><br>paolino<br><br><br><div class="gmail_quote">2012/7/8 Sebastián Krynski <span dir="ltr"><<a href="mailto:skrynski@gmail.com" target="_blank">skrynski@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok , thanks for the answers, I understand now what liftM2 does.<div> In this case would it be silly to use combinerPred (and maybe a newType Predicate a = a -> Bool) for the sake of readability or shoud I stick with</div>
<div>a -> Bool and liftM2?</div><div><br></div><div>thanks, Sebastián</div><div><br></div><div><br></div><div><br><div class="gmail_quote">2012/7/6 Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu" target="_blank">byorgey@seas.upenn.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Fri, Jul 06, 2012 at 03:17:54PM -0300, Felipe Almeida Lessa wrote:<br>
> On Fri, Jul 6, 2012 at 2:11 PM, Sebastián Krynski <<a href="mailto:skrynski@gmail.com" target="_blank">skrynski@gmail.com</a>> wrote:<br>
> > As I was using predicates (a -> bool) , it appeared the need for combining<br>
> > them with a boolean operator (bool -> bool -> bool) in order to get a new<br>
> > predicate<br>
> > combining the previous two. So I wrote my function combinerPred (see code<br>
> > below). While I think this is JUST ok, i'm feeling a monad in the air.<br>
> > So.. where is the monad?<br>
> ><br>
> > combinerPred :: (a -> Bool) -> (a -> Bool) -> (Bool -> Bool -> Bool) -><br>
> > (a -> Bool)<br>
> > combinerPred pred1 pred2 op = \x -> op (pred1 x) (pred2 x)<br>
><br>
> That's the `(->) a` monad:<br>
><br>
> import Control.Applicative<br>
><br>
> combinerPred :: (a -> Bool) -> (a -> Bool) -> (Bool -> Bool -><br>
> Bool) -> (a -> Bool)<br>
> combinerPred pred1 pred2 op = op <$> pred1 <*> pred2<br>
<br>
</div></div>By the way, I find it more natural to make 'op' the first argument,<br>
because it is more useful to partially apply combinerPred to an<br>
operation that it is to some predicates. Also, in that case<br>
combinerPred is simply liftA2:<br>
<br>
import Control.Applicative<br>
<br>
combinerPred :: (Bool -> Bool -> Bool) -> (a -> Bool) -> (a -> Bool) -> (a -> Bool)<br>
combinerPred = liftA2<br>
<span><font color="#888888"><br>
-Brent<br>
</font></span><div><div><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>