Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If "List" is a monoid, what is its "set"?

Tags:

haskell

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!

like image 891
Andriy Drozdyuk Avatar asked Oct 17 '12 04:10

Andriy Drozdyuk


People also ask

Is list a monoid?

Strings, lists, and sequences are essentially the same monoid.

How do you prove a set is a 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.

What are monoids in Haskell?

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.

Is string a monoid?

Well, strings are a monoid under concatenation, so the mapping transformed a monoid (Text) to another monoid (string).


1 Answers

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.

like image 179
sepp2k Avatar answered Oct 15 '22 13:10

sepp2k