Monad: Why does Identity matter, what's going to happen if there's no such special member in a set?

157 views Asked by At

I'm trying to learn the concept of monad, I'm watching this excellent video Brian Beckend trying to explain what is monad.

When he talks about monoid, it's a collection of types, it has a rule of composition, and this composition has to obey 2 rules:

  1. associative: x @ (y @ z ) = (x @ y) @ z
  2. a special member in the collection: x @ id = x and id @ x = x

I'm using @ symbol representing composition. id means the special member.

The second point is what I'm trying to understand. why does this matter ? what if there's no such special member ?

When I learn new concept, I always try to relate these abstract concept to some other concrete things, so that I can fully understand and learn them by heart.

So what I'm trying to relate monad and monoid to is lego. So all the building blocks in a lego set forms a collection. and the composition rule is composite them into new shape of building blocks. and it's obvious the composition obey the first rule: associative. But there's no special building block which can composite with other building block and get the same back. So it fails to obey the second rule.

But lego is still highly composable. What has been missing or lack when lego fails to obey the second rule ? What is the consequence ?
Or put it this way, comparing to other monoid which obey all those rules. What feature does other monoid has but lego doesn't ?

2

There are 2 answers

0
Bassel Mabsout On

The empty Lego could be considered as id but then you will have to accept that empty space is Lego. But yes if you don't want id like @sclv wrote, it would be a semigroup.

0
sclv On

A monoid without an identity element is called a semigroup and its still a fine and useful construct. It just gives us something different. Consider, for example, a fold on a list. We can do this by mapping every element of a list to a monoid and then composing them all. But if you only have a semigroup, you can't fold on a possibly empty list.

Consider another example -- the integers greater than zero, versus the integers greater than or equal to zero. In the latter case we have a monoid, since zero is literally our zero element. So I can solve for example, the equation "5 + x = 5". In the former case, with a semigroup, I can't solve that equation. Or I can say "you have no apples, I then give you five apples, how many do you have?" In a world without zero, we have to assume everyone starts with some apples to begin with! So, for the same reasons having a zero lying around is important with numbers, it is handy to have a "generalized zero" hanging around with more abstract algebraic structures.

(Note this doesn't mean one or the other is "better" -- just that they are different, and the extra structure, when available, can come in handy. Also note that there is a universal way to turn a semigroup into a monoid by adding a zero element, so since all semigroup results lift into the 'completed' results on monoids, it tends to be more convenient, typically, to just treat things in terms of the latter.)