Michael Arntzenius
http://www.rntz.netA binary operator
that's associative
with an identity element.
a · b
Integer addition, +
Set union, ∪
String concatenation, ⧺
Integer maximum
Division, /
(a · b) · c = a · (b · c)
Integer addition, +
Set union, ∪
String concatenation, ⧺
Integer maximum
Division, /
(a/b)/c ≠ a/(b/c)
a · id = id · a = a
Integer addition, +, with 0
Set union, ∪, with {}
String concatenation, ⧺, with ""
Integer maximum no least integer
Division, /
(a/b)/c ≠ a/(b/c)
Associative binary operators with identity.
Matrix multiplication
Merging sorted lists (merge step in mergesort!)
Unix commands under |
, with cat
Composing functions of type (A → A), with (λx.x)
Regular expressions under choice ("|" in (a|b))
CFGs under choice ("|" in A ::= B | C)
Functions for free
Parallelization / MapReduce
Starting point for exploring algebra
instance Monoid String where
mappend = (++) -- ++ is the operator
mempty = "" -- "" is the identity
Get this for free!
mconcat ["monoids", " are ", "great"]
-- Evaluates to "monoids are great"
mconcat
Split the list in half;
send each half to a different processor;
recurse!
Once both halves return, mappend
their
results together.
The reduce step is a distributed, parallel mconcat
Associative binary operators with identity
Turn up everywhere
Make the "reduce" in map-reduce go
A binary operator
that's associative
and commutative
and idempotent
with an identity element.
A monoid
that's commutative
and idempotent.
Integer addition, +, with 0
Set union, ∪, with {}
String concatenation, ⧺, with ""
Integer maximum
no least integer
Division, /
(a/b)/c ≠ a/(b/c)
a · b = b · a
Integer addition, +, with 0
Set union, ∪, with {}
String concatenation, ⧺, with ""
Integer maximum
no least integer
Division, /
(a/b)/c ≠ a/(b/c)
a · a = a
Integer addition, +, with 0
1 + 1 = 2
Set union, ∪, with {}
String concatenation, ⧺, with ""
Integer maximum
no least integer
Division, /
(a/b)/c ≠ a/(b/c)
Natural numbers under maximum
Booleans under logical "or"
N-bit integers under bitwise "or"
Bloom filters under union
Functions for free
Distributed programming
(where they are called CvRDTs)
Convergent replicated datatype
Used to implement eventually-consistent systems
Core idea: Allow changes in any order, possibly multiple times, yet guarantee the same result