8

I read in cats documentation about typeclasses Apply and Applicative. I wonder why the library provides two separate type classes instead of just one type class Applicative, which would extend Functor and add ap ? Does anybody use Apply that is not Applicative ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

12

Applicative provides the pure method, which is a way to "get in". Otherwise, although you could convert F[A] to F[B], either with A => B (via map) or F[A => B] (via ap), you don't have the capacity to put anything inside an F. So you're limited to letting others do it for you.

The difference with Applicative is that you can put things in, starting from nothing.

Since either can be useful ("you are empowered to put things into an F" and "no, keep your hands off, and operate on what you're given"), Applicative and Apply are separate typeclasses.

Rex Kerr
  • 166,841
  • 26
  • 322
  • 407
  • Thank you. I think I got it. Could you give an example of using `Apply` that is not `Applicative` (as in "keep your hands off, and operate on what you're given") ? – Michael Apr 25 '16 at 19:10
  • You can imagine all kinds of cases. For example, if you had an error type that you wanted to process but you didn't want it to be able to generate any new errors or use any information that wasn't from an error context, you could want your error type to have an `Apply` typeclass but not an `Applicative` one. – Rex Kerr Apr 25 '16 at 19:35