[Haskell-beginners] Is there an idiom for this?

akash g akaberto at gmail.com
Mon Nov 16 14:08:04 UTC 2015


And here's the arrow implementation

(pred1 &&& pred2) >>> uncurry (&&)

You need Data.Tuple (for uncurry) and Data.Arrow.


On Mon, Nov 16, 2015 at 5:40 PM, Frerich Raabe <raabe at froglogic.com> wrote:

> On 2015-11-16 12:44, Mark Carter wrote:
>
>> Suppose I want to use an argument twice, as for example in the expression:
>> (\x -> (pred1 x) and (pred2 x))
>>
>> Is there a shorter way of doing this?
>>
>
> I suppose you meant to write '&&' instead of 'and'?
>
> You can write it in an applicative style as
>
>   (&&) <$> pred1 <*> pred2
>
> If you like, you can shorten that a bit using 'liftA2' as
>
>   liftA2 (&&) pred1 pred2
>
> but I personally tend to like the former version better.
>
> --
> Frerich Raabe - raabe at froglogic.com
> www.froglogic.com - Multi-Platform GUI Testing
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151116/2bed0de2/attachment.html>


More information about the Beginners mailing list