DEV Community

Discussion on: Explain what a monoid is Like I'm Five

Collapse
 
nestedsoftware profile image
Nested Software • Edited

I don’t really like the term monoid because it sounds like something out of quantum field theory when the reality is pretty simple.

The two main characteristics of monoids are associativity and identity. For example, let's consider numbers under addition:

(3 + 2) + 6 = 3 + (2 + 6) (associativity)
100 + 0 = 100 (identity)
0 + 100 = 100 (identity)

Numbers are monoids under addition where 0 is the identity element (adding 0 to a number produces the original number).

Try it with multiplication over numbers and concatenation over lists, since those are also monoids. What’s the identity element in each case?

How about subtraction?

Note that you can't say that numbers (or anything else) are or are not monoids without specifying a binary operation (i.e. an operation with 2 arguments) on them as well. Something may be a monoid under a given operation but not a monoid under a different operation.