Search code examples
haskelloperatorsmonoidsbinary-operators

Is my understanding of monoid valid?


So, I'm learning Haskell at the moment, and I would like to confirm or debunk my understanding of monoid.

What I figured out from reading CIS194 course is that monoid is basically "API" for defining custom binary operation on custom set.

Than I went to inform my self some more and I stumbled upon massive ammount of very confusing tutorials trying to clarify the thing, so I'm not so sure anymore.

I have decent mathematical background, but I just got confused from all the metaphors and am looking for clear yes/no answer to my understanding of monoid.


Solution

  • From Wikipedia:

    In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single associative binary operation and an identity element.

    I think your understanding is correct. From a programming perspective, Monoid is an interface with two "methods" that must be implemented.

    The only piece that seems to be missing from your description is the "identity", without which you are describing a Semigroup.

    Anything that has a "zero" or an "empty" and a way of combining two values can be a Monoid. One thing to note is that it may be possible for a set/type to be made a Monoid in more than one way, for example numbers via addition with identity 0, or multiplication with identity 1.