4 ms·
The basic analogy between them is this: A monoid is something where you take two things and multiply them to get one thing. 2 x 3 = 6 In a monad, you take a d
by edflsafoiewq 5y ago
The basic analogy between them is this:
A monoid is something where you take two things and multiply them to get one thing. 2 x 3 = 6
In a monad, you take a doubly-nested thing and "multiply" and get a singly-nested thing: [[a,b],[c]] => [a,b,c]
The monoid laws say that, though you can multiply in different ways, it doesn't matter what order you do it, the end result is the same: (2 x 3) x 4 = 2 x (3 x 4)
The monad laws say the same thing: the order you do the "un-nesting" doesn't matter:
Inner-most first:
[ [[a,b],[c]], [[d]] ] => [ [a,b,c], [d] ] => [a,b,c,d]
Outer-most first:
[ [[a,b],[c]], [[d]] ] => [ [a,b],[c], [d] ] => [a,b,c,d]
-----
If you take the definition of a monoid, which has stuff like
M is a type
multiply : M x M -> M (multiplies two elements)
what it means to do it "in the category of endofunctors" is it changes into
M is an endofunctor, a is any type, Ma is M applied to a
multiply : M(Ma) -> Ma ("multiplies" doubly-nested element)
and when you do these changes for the whole definition of a monoid, what you get is exactly the definition of a monad.