"Shortcut" for f (g x) (g x)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Baa
Reply | Threaded
Open this post in threaded view
|

"Shortcut" for f (g x) (g x)

Baa
Hello, All!

Does Haskell have some "short-form" for such call: `f (g x) (g x)`, for
example:

  compare (snd x) (snd x)

Looks like combinatory logic or `ap` but not exactly...

===
Best regards, Paul
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: "Shortcut" for f (g x) (g x)

Mihai Maruseac
You can use `liftM2 f g g`

For the example you mentioned, there's also

    compare `on` snd

or

    comparing snd

with the proper imports (Data.Ord, Data.Function)

On Mon, Dec 4, 2017 at 8:31 AM, Baa <[hidden email]> wrote:

> Hello, All!
>
> Does Haskell have some "short-form" for such call: `f (g x) (g x)`, for
> example:
>
>   compare (snd x) (snd x)
>
> Looks like combinatory logic or `ap` but not exactly...
>
> ===
> Best regards, Paul
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



--
Mihai Maruseac (MM)
"If you can't solve a problem, then there's an easier problem you can
solve: find it." -- George Polya
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: "Shortcut" for f (g x) (g x)

Dániel Arató
In reply to this post by Baa
Hi!

I think you're looking for Data.Function.on:
http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Function.html#v:on

On 04/12/2017, Baa <[hidden email]> wrote:

> Hello, All!
>
> Does Haskell have some "short-form" for such call: `f (g x) (g x)`, for
> example:
>
>   compare (snd x) (snd x)
>
> Looks like combinatory logic or `ap` but not exactly...
>
> ===
> Best regards, Paul
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: "Shortcut" for f (g x) (g x)

Baa
Oh, yes! Exactly, thanks to all!!

> Hi!
>
> I think you're looking for Data.Function.on:
> http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Function.html#v:on
>
> On 04/12/2017, Baa <[hidden email]> wrote:
> > Hello, All!
> >
> > Does Haskell have some "short-form" for such call: `f (g x) (g x)`,
> > for example:
> >
> >   compare (snd x) (snd x)
> >
> > Looks like combinatory logic or `ap` but not exactly...
> >
> > ===
> > Best regards, Paul
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: "Shortcut" for f (g x) (g x)

Jeffrey Brown
This led me to look up the definition of on and discover that punctuation can be used as a variable name for an operator!

On Mon, Dec 4, 2017 at 11:51 AM, Baa <[hidden email]> wrote:
Oh, yes! Exactly, thanks to all!!

> Hi!
>
> I think you're looking for Data.Function.on:
> http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Function.html#v:on
>
> On 04/12/2017, Baa <[hidden email]> wrote:
> > Hello, All!
> >
> > Does Haskell have some "short-form" for such call: `f (g x) (g x)`,
> > for example:
> >
> >   compare (snd x) (snd x)
> >
> > Looks like combinatory logic or `ap` but not exactly...
> >
> > ===
> > Best regards, Paul
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



--
Jeff Brown | Jeffrey Benjamin Brown
Website   |   Facebook   |   LinkedIn(spammy, so I often miss messages here)   |   Github   

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners