Meet the Applicative typeclass. It lies in the Control.Applicative module and it defines two methods,
pure and <*>
. It doesn't provide a default implementation for any of them, so we have to define them both if we want something to be an applicative functor.
I am trying to understand who is using pure
function. I do use (<*>)
function for which applicative functors are most useful for. But I am not sure who really uses pure
.
I read something like pure (+3) <*> Just 10
but it can be written as Just (+3) <*> Just 10
too.
Above is just one confusion of too many I have. What is the true purpose of defining pure
and when do I get to use it (or) who is already using it?
pure
encapsulates a value into an arbitraryApplicative
functor. Hence,pure 0
can mean any of:Just 0
,[0]
,\_ -> 0
,(mempty, 0)
, etc. Also note thatreturn = pure
. – Dannyu NDospure
can be used to get a kind of polymorphism. Thank you :) – Sumanth Kumar Mora