7

Is there a way to make applicative uses of <$> and <*> look nice when dealing with infix operators? I think that

((++) <$> a <*> ((++) <$> b <*> c ))

looks much more cluttered then

a ++ b ++ c

so I wonder if there is a nicer way.

hugomg
  • 68,213
  • 24
  • 160
  • 246

3 Answers3

12
(<++>) = liftA2 (++)
a <++> b <++> c

or

liftA2 (++) a $ liftA2 (++) b c
singpolyma
  • 10,999
  • 5
  • 47
  • 71
6

See Thomas Davie's InfixApplicative package, which provides a general syntactic trick, rather than having to define a new operator for each lifting.

Conal
  • 18,517
  • 2
  • 37
  • 40
  • 2
    The documentation is a bit mangled. I *think* the OP's example would translate as `a <^(++)^> (b <^(++)^> c)` --- can you confirm/deny? – dave4420 Oct 02 '12 at 09:04
3

SHE lets you write

(|a ++ (|b ++ c|)|)

if that's any use. Of course, there's some overhead to introducing a preprocessing layer.

pigworker
  • 43,025
  • 18
  • 121
  • 214