Search code examples
scalascala-catscategory-theory

MonoidK and Monad relation


I'm trying to understand well known phrase A monad is just a monoid in the category of endofunctors and map some category theory concepts to cats library.

There is a MonoidK typeclass in cats and it's polymorphic on combineK method. So one instance of this typeclass looks like monoid in the category of endofuctors if we parametrize it with functor.

What is the difference between MonoidK and Monad in terms of category theory if we assume that we can parametrize MonoidK only by functors?


Solution

  • There are two notions of monoid: monoid in algebra and monoid in category theory. Latter are more abstract version of former. Former can be considered as very specific partial case of latter. Let's call them monoid (1) and monoid (2).

    MonoidK is monoid (1) for higher-kinded F[_]. You know how to "multiply" two elements of type F[A] and the "unit" of type F[A].

    Monad is monoid (2) for functors. You know how to "flatten" F[F[A]] into F[A] and how to "pack" A into F[A].