Studying functors, applicative functors and monads in Haskell, I found this definition on Wikipedia:
In functional programming, specifically Haskell, an applicative functor is a structure that is like a monad (
return
,fmap
,join
) withoutjoin
, or like a functor withreturn
.
I can't understand: it seems to me that providing return
(i.e. pure
) to a functor is not sufficient to obtain an applicative functor, because you need to provide ap
(i.e. <*>
) too, which cannot be defined in terms of fmap
and return
only. Did I miss something or Wikipedia's definition is not absolutely correct?
EDIT 2017-02-08: I found other useful insights on this question in this answer.
The article was not correct. Assume we have a monad
m
withoutjoin
, or a functor withreturn
. We can definepure
immediately:We cannot, however, define
(<*>)
withfmap
andreturn
only. All we have isfmap
, so we would end up withm (m a)
if we try to use anm (a -> b)
. At that point we needjoin
or its equivalent(>>=)
:An applicative functor is like a functor with
return
andap
, but nojoin
. So yes, you were completely right, Wikipedia missed the operation of applicative (see the original paper).By the way, if you add only
pure
, you get a pointed functor. The typeclassopedia provides a better overview overApplicative
than the Wikipedia article, though.You are correct, applicative functors require
<*>
as well aspure
for a minimal definition. It's worth noting that we can getfmap
from those, though:Similarly we can get the applicative definition from monads:
You could look at applicatives functors a generalization of functors to multi argument functions or as combining values with context horizontally: