Beyond Monad: The Applicative Interface

Ross
The Startup
Published in
8 min readAug 11, 2020

--

Photo by Paweł Czerwiński on Unsplash

I’m in love with functional concepts in programming. And with good cause — functional programming is the future of software development, not just in JS but in systems as well (case in point, Rust, which Microsoft has now adopted). I’ve already described Monad as an interface. In this article I’d like to explain the Applicative type in the same way. Like I’ve said in the Monad Interface, in JS there aren’t actually interfaces like we have in C-Family languages. And there’s no compile-time checking of your adherence to your conceptual interfaces. But it’s really convenient to think in interfaces anyway, because they abstract away our problems into a small concept we can easily reason about. In JS we need to take some extra steps as the developer to ensure that we have upheld an interface’s contract, but it is well worth it to do so.

The Applicative Interface is very simple, even simpler than the Monad Interface, but I think it’s even more powerful because it’s actually more functional:

Applicative<A, B> {
ap(ft: Functor<A>) ⟶ Functor<B>
static of(f: Function<A> ⟶ B) ⟶ Applicative<A, B>
}

static in this case is my way of denoting that of should be a member related to the type itself, not an instance method. And just for posterity, I’ll throw in the Functor Interface:

Functor<A> {
map(f…

--

--

Ross
The Startup

Programming maniac, #JavaScript zealot. I'm crazy about #FunctionalProgramming and I love Rust. ETH coffee fund: 0x0c37584674e7143e03328254232102973a9cd468