Pedantic question about monads

We talk about the List monad, among others. List is defined (as I understand) as a parameterized type. I.e., List is not defined but rather List[A] is defined. Which one is the monad? Is it List, or List[A] or List[Int] or a particular object such as List(1,2,3,4) ?

Hmm. Keeping in mind that I’m not a Deep Category Theory Guru, I tend to think of a Monad as being necessarily a Functor, which means that it’s a type constructor over another type. And the Monad is the type, not an object. So I would say List[A] – a type that is a Functor over some other type, and provides the map, flatMap and (conceptually) pure operations.

@jducoeur, if I understand your suggestion correctly, you think of List[A] as being a monad for each A ? I.e., a family of monads, one for each A, rather than thinking of the set of all such List[A] as the monad?

Ah, I see what you’re asking. No, I would say that List is a Monad that operates on arbitrary types A. But again, I’m not an authority on this subject…

Assuming the original question was related to the categorical definition of Monad, then this is correct. List is the functor part of the monadic functor.

It is a functor from the category Scala to itself (an endofunctor), where in this category the objects are ‘Scala types’, and the List functor is transforming all objects (type A for all A in the category) into new objects (type List[A]).

The two required natural transformations (I->T and T∘T->T) are given by the implementations of pure and flatten, respectively, in this case for the List functor.

So, List, as a lawful functor, along with lawful implementations (for List) of the pure and flatten methods, IS the monad.

See also https://en.wikipedia.org/wiki/Monad_(category_theory) for more detail, although that’s not exactly a seeker-friendly resource.

4 Likes