Scala 中的 monoid 与 monad
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9745994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
monoid vs monad in Scala
提问by Bober02
I have recently tried to find a good source on the difference between monads and monoids.
我最近试图找到关于 monads 和 monoids 之间区别的好资料。
Could someone provide a link to a good resource on this or perhaps take one's time to elaborate on the similarities/differences?
有人可以提供指向此方面良好资源的链接,或者花时间详细说明相似之处/不同之处吗?
回答by Daniel C. Sobral
Monads are monoids in the category of endofunctors.Therefore, a monad is just one example of monoid, which is a more general concept.
单子是内函子范畴中的幺半群。因此,monad 只是幺半群的一个例子,幺半群是一个更一般的概念。
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 learnthem. There's ton of material about it on the internet, easily googled.
而且,虽然这在技术上可能是正确的,但最简单的答案是 monads 和 monoids 实际上彼此完全不同,您不应该试图了解它们之间的区别,而应该学习它们。互联网上有大量关于它的材料,很容易用谷歌搜索。
回答by Dmitri Zaitsev
See this answeron 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.
请参阅此答案,了解为什么 monad 是幺半群类别中幺半群的特例。然而,后者是通过二元运算和单元定义的经典幺半群的推广。Monad 不是经典的幺半群。有关更多详细信息和解释,请参阅答案。

