3 ms·
>A functor takes a function, and applies it to the inside of a context, but all of a sudden now a functor can't take a function and apply it to the inside of a
by chongli 14y ago
>A functor takes a function, and applies it to the inside of a context, but all of a sudden now a functor can't take a function and apply it to the inside of a context.
Where you're getting mixed up is in the distinction between Functors and Applicative Functors. You can think of an Applicative Functor as one which allows you to apply its contents to other things. One function which must be defined for all Applicative Functors is:
(<*>) :: f (a -> b) -> f a -> f b
Looking at the type signature, this is a function of two arguments. The first argument is an Applicative Functor containing a function. The second argument is the same functor containing a value to which that function may be applied. What does this function do? It simply applies the function and returns the result, wrapped in the same Functor. Thus:
Just (+5) <*> Just 4
>>> Just 9
This is very much analogous to typical function application:
(+5) 4
>>> 9
Which is why the function (<*>) is usually pronounced "ap" or "applied over".