Skip to content

Instantly share code, notes, and snippets.

@arosien
Created September 22, 2017 23:11
Show Gist options
  • Save arosien/a732f865774ff731a0a0f761004d0945 to your computer and use it in GitHub Desktop.
Save arosien/a732f865774ff731a0a0f761004d0945 to your computer and use it in GitHub Desktop.
free monoid
@gfixler, free monoid is the easiest and helps generalize the whole "free" thing
let's make a monoid that is a monoid for *anything*
but wait, that doesn't sound possible, everything that can be a monoid has its own rule, that's the whole point
but if you wanted to make a monoid for anything, you can just be really lazy, and instead of actually adding things together, you just collect all the things you want to add
"you want to add an A and an A, sure, the answer is: here's your two A's" HA HA HA free monoids rule
and so on: to add As you just collect all the As and call the collection of them the answer
so it's a monoid with this bogus addition, but it can handle anything
what's does it look like? a list!
the free monoid is a list. the zero is the empty list, and you just append lists together!
other free things are just like that... they cheat, but they can be a free X for anything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment