Witchcraft v0.5.0 Witchcraft.Monoid
Monoids are a set of elements, and a binary combining operation (op) that
returns another member of the set.
Properties
Associativity
- Given a binary joining operation
•, - and all
a,b, andcof the set, - then:
a • (b • c) == (a • b) • c
Identity element
- Unique element (
id, sometimes called the ‘zero’ of the set) Behaves as an identity with
opidentity = 0 op = &(&1 + &2) # Integer addition append(34, identity) == 34
identity = 1 append = &(&1 * &2) # Integer multiplication append(42, identity) == 42
Counter-Example
Integer division is not a monoid. Because you cannot divide by zero, the property does not hold for all values in the set.