3 ms·
While monoids are explicitly identified in some functional languages, they don't have to be. Monoids just exist whenever the axioms are satisfied. A monoid is
by Maybestring 9y ago
While monoids are explicitly identified in some functional languages, they don't have to be. Monoids just exist whenever the axioms are satisfied.
A monoid is a set, and an operation for combining elements from the set, that satisfy a few properties.
Closed: For every combination of elements, the result of combination is in the set.
Identity: There is an element of the set that when combined with any other element, results in that same other element.
Associative: For any elements a,b,c a+(b+c) = (a+b)+c
Examples are helpful here. I'll list a few as (set,operation,identity)
(Integers,+,0)
(Integers,*,1)
(Strings,&,"")
(Lists,&,[])
(functions t->t, function composition, identity function)
(Bool,and,True)
(Bool,or,False)
(Bags of candy and the empty bag, dumping bag a into bag b, the empty bag)