Monad laws in category theory vs Haskell

621 Views Asked by At

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.

1

There are 1 best solutions below

0
On

I know the question is a bit old, but the correspondance 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.