3 ms·
You have a value of a certain type. You have another value of the same type. If there exist a function (let's call it "combine") that combines those two value
by zephyz 9y ago
You have a value of a certain type.
You have another value of the same type.
If there exist a function (let's call it "combine") that combines those two values and emits a third value of the same type.
AND
There exists a value of this type that does nothing when used as argument to this "combine" function.
then your type is a monoid. (basically)
- jerf 9y agoYou left off the associativity; you need (a + (b + c)) == ((a + b) + c), where + is the combining operation.
- zephyz 9y agoI did. I left it out for two reasons: - the comment asked for a "simpler" explanation and associativity isn't a specially simple concept if you are not familiar with it and does not really help understand the core idea of a monoid. - in practice, monoid associativity isn't checked. Most type system aren't able to express it. Therefore, whenever you encounter a monoid you have no guarantee that it is indeed associative.
- feanaro 9y agoThere may be no guarantee, but that doesn't make a structure without associativity any more of a monoid, nor is having an identity element without associativity the core of idea of a monoid. If anything, associativity is the more important part of the concept since without an identity element, you are still left with a semigroup.