For people who haven’t done abstract algebra, don’t be put off by the word “monoid”. A monoid in algebra is just a set with some associative binary operation and an identity element. Mathematicians in the 19th and 20th centuries realised you can study these types of structures and prove things which are true for all of them rather than having to do each one separately, and that led to “abstract algebra”.
So for example, if I have the integers and multiplication, this is a monoid[1]. The identity element is zero, which is an integer, and multiplication is an associative binary operation. It takes two integers and returns an integer.
Once you realise you have a monoid, if you do maths that only relies on the monoid properties then it applies to all monoids, so you could drop a different monoid in there and everything would still work. This ends up being very much like how typeclasses work in Haskell or traits in Rust.
[1] For the curious, it’s not a “group” because the integers don’t have multiplicative inverses. If I have x=2, there is no integer that I can multiply that by to get 1. Integers with addition on the other hand is a group, which is a monoid with the additional property that inverses are present.
bern4444•27m ago
> The identity element is zero
I think the identity element would be 1 for integers and multiplication, right?
0 would be the identity element for integers and addition.
aranchelk•20m ago
That and also why start with multiplication? String concatenation, addition, list concatenation all make more intuitive sense to a working programmer.
What's a straightforward way to combine a bunch of numbers? Just keep multiplying them to get a resulting volume in an ever-higher dimensional space.
seanhunter•38m ago
So for example, if I have the integers and multiplication, this is a monoid[1]. The identity element is zero, which is an integer, and multiplication is an associative binary operation. It takes two integers and returns an integer.
Once you realise you have a monoid, if you do maths that only relies on the monoid properties then it applies to all monoids, so you could drop a different monoid in there and everything would still work. This ends up being very much like how typeclasses work in Haskell or traits in Rust.
[1] For the curious, it’s not a “group” because the integers don’t have multiplicative inverses. If I have x=2, there is no integer that I can multiply that by to get 1. Integers with addition on the other hand is a group, which is a monoid with the additional property that inverses are present.
bern4444•27m ago
I think the identity element would be 1 for integers and multiplication, right?
0 would be the identity element for integers and addition.
aranchelk•20m ago
What's a straightforward way to combine a bunch of numbers? Just keep multiplying them to get a resulting volume in an ever-higher dimensional space.