“A monad is a monoid in the category of endofunctors”

What “functor” means

When we talk about functors, we often say something like:

a functor F is something that can lift a function A → B into F<A> → F<B>

This phrasing implies that fmap itself is the functor. This sets us up for failure when we then try to describe why “a monad is an functor monoid,” because it makes it sound like a monad is a monoid on fmap functions. But it’s actually a monoid on the half of the definition of functor that we omitted.

A functor consists of two things. A functor is the pair of:

  1. A type constructor (F), and
  2. An fmap function

The monoid is over type constructors

A monad involves a monoid on functor type constructors, not on functor fmaps. The monoid means you can combine F<·> with F<·>, and the result F<F<·>> is isomorphic to F<·>.

In Haskell, this combining operation corresponds to the function called join.

Type Classes offers courses and projects to get you started and make you an expert in FP with Haskell. For $29/month, you get access to the complete archive and all the latest content.