#readwise
# Monoids

## Metadata
- Author: [[Mark Seemann]]
- Full Title: Monoids
- URL: https://blog.ploeh.dk/2017/10/06/monoids/
## Summary
This is article is a part of a bigger blog series that covers various topics from category theory. The series includes other articles on the topic of monoids. Here's a list, retrieved on March 17, 2023.
- Angular addition monoid
- Strings, lists, and sequences as a monoid
- Money monoid
- Convex hull monoid
- Tuple monoids
- Function monoids
- Endomorphism monoid
- Maybe monoids
- Lazy monoids
- Monoids accumulate
## Highlights
**What do addition (40 + 2) and multiplication (6 * 7) have in common?
They're both associative, binary operations, with a neutral element.
That's all it takes to form a monoid. Associativity and the existence of a neutral element is sometimes referred to as the monoid laws.** It's worth noting that a monoid is a combination of a data type (or set) and an operation. It's not a data type in itself, but rather a function (or method) that operates on that data type. For example, addition and multiplication are two different monoids that both work on numbers. ^zm5eiz
---
That an operation is binary means that it works on two values.
---
**In order to form a monoid, the binary operation must be associative. This simply means that the order of evaluation doesn't matter.**
---
**The third rule for monoids is that there must exist a neutral value. In the normal jargon, this is called the identity element,** ... The identity element is a value that doesn't 'do' anything. For addition, for example, it's zero, because adding zero to a value doesn't change the value:
---
There are plenty of examples of monoids. The most obvious examples are addition and multiplication, but there are more. Depending on your perspective, you could even say that there's more than one addition monoid, because there's one for integers, one for real numbers, and so on. The same can be said for multiplication.
There are also two monoids over boolean values called all and any.
---
In essence, **if you have a data type that 'behaves like a number', you can probably make it a monoid.**
---