3 ms·
What you have described is a semigroup. Sometimes an application might naturally involve semigroups and sure, they share the benefits of associativity with mono
by theoh 8y ago
What you have described is a semigroup. Sometimes an application might naturally involve semigroups and sure, they share the benefits of associativity with monoids. Semigroups generalise monoids, which are one step further up on the ladder to full groups.
Monoids occur more frequently in practice both because it's often practically useful and semantically meaningful to have an "empty" value (the identity) when accumulating results. So even if the application has an underlying semigroup structure, you might sometimes want to use a sum type to add an identity and make it into a monoid:
"Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e • s = s = s • e for all s ∈ S."
So from a programming point of view, the monoid is a handier pattern than the semigroup, and you can almost always turn a semigroup into a monoid if that would make things more convenient.
There are a couple of articles here that make a weak case for the applicability of semigroups in software: https://blog.ploeh.dk/2017/11/27/semigroups/ https://blog.ploeh.dk/2017/11/27/semigroups/