28

I have recently tried to find a good source on the difference between monads and monoids.

Could someone provide a link to a good resource on this or perhaps take one's time to elaborate on the similarities/differences?

nbro
  • 15,395
  • 32
  • 113
  • 196
Bober02
  • 15,034
  • 31
  • 92
  • 178
  • 3
    There is so much content about monads & monoids that i guess everybody has its own "good source". My triade is : this [SO question](http://stackoverflow.com/questions/3870088/a-monad-is-just-a-monoid-in-the-category-of-endofunctors-whats-the-problem), [Monads Are Not Metaphors](http://www.codecommit.com/blog/ruby/monads-are-not-metaphors) by Daniel Spiewak and [Monads are Dominoes](http://apocalisp.wordpress.com/2011/07/01/monads-are-dominoes/) by Rúnar Óli – blouerat Mar 17 '12 at 00:21
  • In category theory "For any category C, the category [C,C] of its endofunctors has a monoidal structure induced by the composition. A monoid object in [C,C] is a monad on C." - from https://en.wikipedia.org/wiki/Monoid_%28category_theory%29. See https://en.wikipedia.org/wiki/Monad_%28category_theory%29 for definition of monad in category theory. –  Jun 23 '15 at 00:07

2 Answers2

29

Monads are monoids in the category of endofunctors. Therefore, a monad is just one example of monoid, which is a more general concept.

And, though that might be technically true, the most simple answer is that monads and monoids are really nothing like each other, and you shouldn't be trying to learn the difference between them, but just learn them. There's ton of material about it on the internet, easily googled.

Community
  • 1
  • 1
Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
  • 4
    I surprises (and intimidates) me how mathematically relatively related ideas can turn out to be radically different in all practical terms when applied to programming languages. – Erik Kaplun Feb 25 '14 at 19:12
  • 2
    This answer in another question by the community wiki is one of the best and most concise http://stackoverflow.com/a/7829607/541202 – Traveler Dec 18 '14 at 14:37
  • More precisely "For any category C, the category [C,C] of its endofunctors has a monoidal structure induced by the composition. A monoid object in [C,C] is a monad on C." - from https://en.wikipedia.org/wiki/Monoid_%28category_theory%29. See https://en.wikipedia.org/wiki/Monad_%28category_theory%29 for definition of monad in category theory. –  Jun 22 '15 at 23:58
  • 1
    "Monads are monoids in the category of endofunctors." That's really confusing. Aren't all functors in programming ultimately endofunctors (since the only category is that of types and functions) ? If so, does that ultimately mean that every monoid on programming is also a monad? – 0x6C38 Oct 18 '16 at 06:08
  • @0x6C38 If you find it confusing you should see this answer: https://stackoverflow.com/a/57537696/1614973 – Dmitri Zaitsev Aug 25 '19 at 12:55
  • @Traveler That answer does not explain why monads are special monoids, see stackoverflow.com/a/57537696/1614973 – Dmitri Zaitsev Aug 25 '19 at 12:59
-2

See this answer on why monads are special cases of monoids in monoidal categories. The latter is, however, a generalization of the classical monoid defined via binary operation and unit. Monad is not a classical monoid. See the answer for more details and explanations.

Dmitri Zaitsev
  • 13,548
  • 11
  • 76
  • 110