--- title: Dysfunctional Programming date: 2025-11-24 modified: 2025-11-24 draft: true summary: Group Theory Adjacent Nonsense for people who slept through high school (me) --- *Group Theory Adjacent Nonsense for people who slept through high school (me)* > A Cringe set is Just a Co-Based set > > \- Unknown So anyway, what the FUCK is a Monad - A monoid in the category of endofunctors - a burrito - a co-comonad Do any of these mean anything? No, so lets start at the beginning # Numbers - In the beginning, there was the empty set - and then Zermelo and Fraenkel said "Let there be a power set of the empty set" - ...which is a line of exploration that will get us nowhere productive for the scope of this work, and is probably something I'll talk about in the future. # Magmas - The easiest Algebraic Structure to explain is The **Magma** - **Definition**: A magma is a set \(M\) with an operation \(\cdot\) that sends \(a,b\in M \to a\cdot b \in M\) - the tl;dr is, you've got a set of stuff, and you can shove any two of those together to make a third thing, as long as it's still in the set, we call this property **closure** - you're probably used to \(\cdot\) meaning multiplication, but that's a fake word that doesn't mean anything - Aside: '\(\cdot\)' is hard to read on its own, hereafter it will be referred to as multiplication or as bottom surgery 'the operation') - The main example of this is the Free Magma, which is basically just a binary tree - In this case, 'multiplying' two binary trees just means concatenating them - Why is this called the Free Magma? I honestly have no clue, Free means *something* here but I haven't figured out what yet. This will not be the last time it comes up. # Monoids - The next step we'll on the Algebraic Structure Skill Tree is the Semigroup, but that's less important to focus on here so I'll fold it into the Monoid Section - When you add Associativity to a Magma, you get a **Semigroup** - Associativity just means that \(a\cdot(b\cdot c) = (a\cdot b) \cdot c\) - A more concrete example of this is natural number addition, \(2+(3+4) = (2+3)+4\) - The proof of this is trivial and left as an exercise to the reader - When you take a Semigroup and add an **Identity** to it, you get a **Monoid** - An identity is just something that you can combine with something and get that same something back out - The easiest way to think of this is that we need something that acts like '1' when you 'multiply' by it - If we go back to the example of adding numbers together, '0' acts as the identity since \(0+x = x\) - Yes, this means that the '1' element of \((\mathbb{N},+)\) is '0' - No, I'm not sorry for coming up with that absolutely dumb ass example - The Free Monoid is strings with concatenation as the operation - Told you 'Free' would come up again - the Identity element here is '', or the empty string - This is closed since adding two strings together always results in a string - This is also associative because Trust Me Bro - Another example of a Monoid is RGBA colors - The identity here is `rgba(0,0,0,0)` since adding clear to any color doesn't change it - Colors are closed under saturating addition since you can add two of them and get a color back* - *Actually I'm sure there's some sort of floating-point nonsense that makes this not true but IEEE 754 can go suck a log - actually you know what, lets pretend that #RRGGBBAA is a real notation that real people use, since it'll let us replace define multiplication as 8-bit saturating addition which is a much more well defined thing to do to colors - RGBA Color addition is associative because I said so - Absolutely unrelated, but I'm pretty sure OKLab isn't closed under the set of displayable colors, which feels cursed but is probably reasonable tbh # Categories - The Magma -> Monoid skill tree (and the several parts of it that I left out), are a scuffed refresher on Group Theory - Up next is Category Theory, which they did not cover in high school; As such I will be spewing a significant amount of hot air out of my ass. # Functors > A category is a collection of "objects" that are linked by "arrows" > > \- [Wikipedia - Category](https://en.wikipedia.org/wiki/Category_(mathematics)) - ...FUCK, I was going to say that, unfortunately Wikipedia's definition is pretty spot on here. - Okay but seriously > In mathematics, abstract nonsense is a nonderogatory term used mainly to describe category theory and homological algebra > > \- Paraphrased from [Wikipedia - Abstract nonsense](https://en.wikipedia.org/wiki/Abstract_nonsense) - Okay forget finding a way to explain it to an audience of (uhhh whatever my audience is, I kinda try to write these at a level high school me could follow along with and not get bored, but I don't actually know what kind of masochist is reading this), I need to figure out how to explain this to me first - I'm back from Wikipedia, and I've returned neither smarter nor wiser, as such we proceed in our endeavors with the rallying cry: "Fuck it, we ball" # Endofunctors # Monads - Examples include: `Future`, `List`, `Option`, `Result` also logging - TODO: find someone who can explain how/why logging and file i/o are monadic ---- # Questions Mira hasn't answered yet and should really get around to before publishing this - Does free just mean the operation is concatenation? - https://en.wikipedia.org/wiki/Free_object - it's supposed to be the 'most generic' - How does using monads deal with side effects, eg Logging, File IO - Do they encapsulate state somehow? how does that work exactly? - what exactly does `Co-` entail