Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to separate Apply and Applicative type classes?

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 ?

like image 737
Michael Avatar asked Apr 25 '16 18:04

Michael


1 Answers

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.

like image 53
Rex Kerr Avatar answered Nov 16 '22 03:11

Rex Kerr