monoid vs monad in Scala
Asked Answered
O

2

29

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?

Offstage answered 16/3, 2012 at 23:58 Comment(2)
There is so much content about monads & monoids that i guess everybody has its own "good source". My triade is : this SO question, Monads Are Not Metaphors by Daniel Spiewak and Monads are Dominoes by Rúnar ÓliCoot
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 en.wikipedia.org/wiki/Monoid_%28category_theory%29. See en.wikipedia.org/wiki/Monad_%28category_theory%29 for definition of monad in category theory.Burgee
A
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.

Almazan answered 17/3, 2012 at 1:34 Comment(6)
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.Vedi
This answer in another question by the community wiki is one of the best and most concise https://mcmap.net/q/45981/-a-monad-is-just-a-monoid-in-the-category-of-endofunctors-what-39-s-the-problemPender
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 en.wikipedia.org/wiki/Monoid_%28category_theory%29. See en.wikipedia.org/wiki/Monad_%28category_theory%29 for definition of monad in category theory.Burgee
"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?Muddleheaded
@Muddleheaded If you find it confusing you should see this answer: https://mcmap.net/q/45981/-a-monad-is-just-a-monoid-in-the-category-of-endofunctors-what-39-s-the-problemArboriculture
@Pender That answer does not explain why monads are special monoids, see https://mcmap.net/q/45981/-a-monad-is-just-a-monoid-in-the-category-of-endofunctors-what-39-s-the-problemArboriculture
A
-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.

Arboriculture answered 25/8, 2019 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.