5

I am new to both category theory and Haskell.

It is well known that, in category theory, Monad can be defined as "a monoid in the category of endofunctors". According to the definition of Monoid in Wikipedia:

enter image description here

But according to the Monad laws in Haskell Wiki, a monad needs to follow three rules:

enter image description here

I think I can roughly understand how the unitor diagram in the definition of Monoid can be expressed as the left identity law and right identity law of Monad in Haskell. But I am not sure how I can infer the associativity law in Haskell only using the definition of Monoid?

EDIT:

I found this page, which states a different set of Monad laws and proves that from these four laws, we can get the three Monad laws in the Haskell Wiki. IMHO, the first law here can be inferred from the pentagon diagram and the second can be inferred from the unitor diagram in the definition of monoid. But I am not sure what are the equivalent definitions in Monoid that translates to the third and fourth laws.

  • 2
    You can't directly because (>>=) doesn't even make sense for an arbitrary monad. You need a strong monad to define (>>=). Either way, (>>=) is not the analogue of $\mu$, join is. – Derek Elkins left SE May 24 '19 at 08:01
  • @DerekElkins, since in Haskell, we can define (>>=) based on join and fmap, can we generalize it to category theory since Monad is indeed an (endo)functor? – Lifu Huang May 24 '19 at 08:09
  • nLab has a short and sweet explanation for how these monad laws follow from the diagram but does it by means of drawing the string diagrams, which might not be useful for you if you haven't met those yet. https://ncatlab.org/nlab/show/monoid

    But since we may always think of a monoid as the homset of a category with a single object, where the binary operation is inherited from composition of morphisms, then the monoid just inherits associativity from the associativity of the morphism composition in the category. (Likewise, the identity law comes from the identity morphism.)

    – Jack Crawford May 24 '19 at 09:46

1 Answers1

2

I know the question is a bit old, but the correspondence can be seen by comparing the laws described in this link (the same provided in the edit) and the Wikipedia article on Monads.

Basically, the laws in 1 mention the endofunctor $M$, 'join' and 'unit', which in Haskell correspond to 'fmap', 'join' and 'return' respectively.

In 2, the endofunctor is called $T$, 'join' is called $\mu$ and 'unit' is called $\eta$. The first law in 1 corresponds to the first law under 'Formal Definition' in 2 and also to the first commutative diagram. The second law in 1 corresponds to the second law and the second commutative diagram in 2. The third and fourth laws are inferred from the fact that $\mu$ and $\eta$ are natural transformations.

rschwieb
  • 160,592