Search⌘ K

Applicative Functors

Explore the concept of applicative functors in functional programming. Learn how these functors wrap functions and apply them to other functors, including techniques for handling functions with multiple arguments using partial application. This lesson clarifies the use of applicative functors and their relation to functors and currying.

Applicative functors

An applicative functor wraps a function. It can apply its function to another functor. For example:

Python 3.8
from oslash import Just
from operator import neg
a = Just(3)
f = Just(neg)
b = f.apply(a)
print(b)

The first thing to know is that this code only works because Just isn’t only a functor, it is also an applicative functor. An ordinary functor doesn’t have an apply method. So, having wrapped our neg function in the applicative functor, f, we can apply it ...