Monoids
- Functional XSLT/XPath/XQuery - #4 Monoid
9 June 2024
Functional XSLT/XPath/XQuery - #4 Monoid
Usually in these sorts of tutorials Monoid comes first, its the simplest, easiest most familiar sort of thing, we don’t really even need code to describe it, its loosely the theory of having something you can composing two things together and getting another thing of the same type, together with an identity element, so in mathematics the integers form a monoid with
+and the identity element is0or we can use multiplication*and1, the set of booleans, i.e.{ True , False }together with the operatorANDform a monoid, where the identity element isTrue, to be honest, these things are rarely used as monoids in functional code, they could be, there just isn’t much use, the things that are usually used as monoids are collections, so in the XPath world this issequence,array,map(and the recently addedmaybe).