[Haskell-cafe] avoiding parens in postfix applicative notation

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Tue Feb 6 14:01:20 UTC 2018

Dear Cafe -

operators <$> and <*> have their precedence
so that this (silly example) works without parens:

  (,) <$> "foo" <*> "bar"

Most of the time, I find that the function
(the first argument) is the largest sub-expression,
so I want to put it last. I can do this

  import Control.Lens.Lens ((<&>))

  "foo" <**> ( "bar" <&> (,) )

but (even ignoring that this pulls in a library
with a ton of dependencies) this needs parens,
and I find this quite ugly when the closing parenthesis
comes at the end of lambda expression
that spans several lines.

One work-around is

  ( "foo" <**> ) $ "bar" <&> (,)

Can this be done in a less noisy way?

- J.W.

PS: Bike-sheddingly, shouldn't this (<&>)
be defined right next to (<$>) ?
There's nothing that would tie it to lenses?
And, (&) right next to ($) ?

More information about the Haskell-Cafe mailing list