
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 guess it depends on the final use cases... you could use currying to
partially evaluate some stuff ready, locked and loaded as it were but the
example you have given shows to distinct functions pres1 and pred2.
I guess the short answer is "yes" but it depends on how you do it!
:)
Sean
On 16 November 2015 at 11:44, Mark Carter
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? _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

You can be cute and use the applicative instance on functions: (&&) <$>
pred1 <*> pred2. I would recommend against such cuteness however and just
write out the arguments.
On Mon, 16 Nov 2015 at 11:54 emacstheviking
I guess it depends on the final use cases... you could use currying to partially evaluate some stuff ready, locked and loaded as it were but the example you have given shows to distinct functions pres1 and pred2.
I guess the short answer is "yes" but it depends on how you do it!
:) Sean
On 16 November 2015 at 11: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? _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

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@froglogic.com www.froglogic.com - Multi-Platform GUI Testing

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
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@froglogic.com www.froglogic.com - Multi-Platform GUI Testing
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (5)
-
akash g
-
Benjamin Edwards
-
emacstheviking
-
Frerich Raabe
-
Mark Carter