Monoid-Augmented FIFOs, Deamortised

pvk.ca

27 points by todsacerdoti a day ago


seanhunter - a day ago

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.

renox - a day ago

Interesting topic, too bad I didn't know about this a few years ago..