Just reading through category theory book, and decided to apply it to haskell.
The author defines Monoid as:
Monoid is a set L equipped with a binary operation *:LxL->L and a distinguished unit element u in L such that etc...
Taking a "List" structure as a monoid, it is clear that binary operation is concat
and unit is []
.
But what is the set M here?
I tried L = {set of all lists}
but I think that leads me into trouble with "is L in L?" question, which seems to be the same problem as sets have.
Or am I thinking of something incorrectly?
EDIT: As pointed out by @applicative, Haskell's lists are monoids called the Free monoids!
Strings, lists, and sequences are essentially the same monoid.
For a set to be a monoid, it must be associative and must have an identity element. I've proved that is it associative but don't know how to prove that it has a identity element. for all (x1,y1,z1),(x2,y2,z2)∈R3.
As we can see, Monoid in Haskell is a typeclass that has three methods: mempty , mappend , and mconcat . mempty is a value that doesn't impact the result when used together with the binary operation. In other words, it's the identity element of the monoid. mappend (or <> ) is a function that puts two monoids together.
Well, strings are a monoid under concatenation, so the mapping transformed a monoid (Text) to another monoid (string).
Instead of saying "List is a Monoid", it would be more accurate to say "For all types a, the type [a]
is a Monoid". So for any particular type a
, your L will be L = {set of all lists of as}
. And with that definition, L can of course not contain itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With