Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

monoid vs monad in Scala

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?

like image 934
Bober02 Avatar asked Mar 16 '12 23:03

Bober02


People also ask

What is the difference between monoid and monad?

Monoid in the category of endofunctors is any endofunctor with operations η and μ, and we call such endofunctor a monad (reminder: objects of that category are endofunctors and arrows are natural transformations). So, monad can be defined in many ways, such as: monoid in the category of endofunctors.

Is every monad a monoid?

@AlexanderBelopolsky, technically, a monad is a monoid in the monoidal category of endofunctors equipped with functor composition as its product. In contrast, classical "algebraic monoids" are monoids in the monoidal category of sets equipped with the cartesian product as its product.

What is a monad in Scala?

Monad in scala are a category of data types. Informally, anything that has a type parameter, a constructor that takes an element of that type, and a flatMap method (which has to obey certain laws) is a monad. A monad is a mechanism for sequencing computations.

What is monoid Scala?

The algebraic structure semigroup is a set and an associated binary operator that combines two elements from the set. A monoid is a semigroup with the added identity element. To build our intuition about monoids, let's encode these definitions in Scala.


1 Answers

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.

like image 179
Daniel C. Sobral Avatar answered Sep 25 '22 04:09

Daniel C. Sobral