6

Perhaps this is not the right place to ask and presumably this question is too 'meta', but is there any reason the <*> (and analogously <$>) function is infix? To my understanding and my knowledge (thus far) of Haskell it does the same as fmap.

So, why is fmap not infix but its Applicative and Functor variant are?

2
  • 3
    Someone or other wrote about <$>, <*>, and =<< all being variations on function application. So it's helpful to give them all vaguely similar syntax. As Cale Gibbard (I think) said, it's unfortunate that $ is right associative while all the other sorts of application are left associative.
    – dfeuer
    Jan 12, 2016 at 21:16
  • 1
    Note that <*> isn't the same as fmap: rather, <$> is actually a synonym for fmap, and <*> is something that is a lot like fmap, but a bit different.
    – amalloy
    Jan 12, 2016 at 23:42

1 Answer 1

13

I think it's mostly motivated by this idiom:

f <$> x <*> y <*> z

Spelled with prefix functions it's a lot less pretty, and you need to know how many applications there are just to start typing:

ap (ap (fmap f x) y) z
3
  • 3
    Though you could of course still write f `fmap` x `ap` y `ap` z. Jan 12, 2016 at 21:03
  • 10
    @leftaroundabout Sure. And if you're going to be doing that all the time, you might as well choose function names that can be used infix. Jan 12, 2016 at 21:04
  • It's also worth mention that <*> has a stronger specification than ap, as it works on all Applicatives, and therefore all Monads, but ap only works on Monads.
    – semicolon
    Apr 11, 2016 at 21:09

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.