Monads and algebras for a monad
Flatten nested finite subsets and verify the unit and algebra laws by explicit calculation.
On this page
The question for today
What you’ll understand
- State both monad unit laws and the associativity law with matching types.
- Verify the finite powerset monad using singleton insertion and union.
- Calculate an algebra structure and distinguish it from the monad multiplication.
A monad records an operation that can introduce structured data and flatten repeated layers of that structure coherently. The flattening is constrained by two unit laws and an associativity law; an arbitrary endofunctor is not enough. Finite subsets provide an example in which every layer is a finite set that can be inspected. An algebra for this monad then interprets a finite collection inside a particular object, such as taking its maximum in an ordered chain.
An endofunctor needs coherent unit and multiplication
A monad on consists of an endofunctor , a natural transformation , and a natural transformation . Both ways of inserting a trivial layer into an already structured object must flatten back to that object. Flattening three layers in either order must agree. The subscripts specify which layer is being manipulated, so the two unit expressions are different maps even when their composites with multiplication coincide.
An adjunction produces a monad with the adjunction's unit and with multiplication . The triangle identities imply the unit laws, while naturality of the counit supplies associativity. This explains one source of monads without claiming that every useful calculation needs the adjunction written down. In the concrete example below, singleton insertion and union can be verified directly, including their compatibility with maps.
The finite powerset monad uses direct images
On FinSet, let be the set of all subsets of . For a function , define by direct image of subsets. This is covariant: direct images preserve identities and compose in the same order as functions. Set , and let take the union of a family of subsets. The empty subset and the empty family are included. Direct image commutes with union and singleton formation, proving naturality of both transformations.
The two unit laws say that unioning a singleton family containing S or unioning the family of singleton subsets of S both recover S. Associativity says membership in the final union is equivalent to membership in some subset belonging to some family, regardless of which union is performed first. Since X is finite, all iterated powersets remain finite; for a three-point X their first two sizes are eight and 256. Inverse image would have the wrong variance for this endofunctor.
An algebra interprets structured data in one object
An algebra for a monad is an object X with a map satisfying and . The first says interpreting a trivial structure returns its original element. The second says interpreting after flattening agrees with interpreting each inner structure and then interpreting the resulting outer structure. These equations involve the algebra map, which has a different target from the monad multiplication.
For the finite powerset monad, a finite chain with a least element becomes an algebra by taking the maximum of a nonempty subset and interpreting the empty subset as the least element. Singleton interpretation is immediate. For a family, the largest element appearing anywhere is also the largest of the inner maxima, with the empty case handled by the least element. More generally these algebras express finite joins with a bottom element; the empty-set convention is part of the laws, not a disposable special case.
Work it through
Interpret a family of subsets in a three-point chain
For ordered normally, let for nonempty S and . Compare the two sides of the algebra law on , and check associativity on a concrete three-layer family.
Union the members of to obtain , whose interpretation is two. Alternatively interpret the three members first: they give two, one, and zero. The outer interpretation of is again two.
For each element x, the singleton has maximum x, proving the algebra unit law at all three points. The empty family interprets through union as zero, consistently with the chosen bottom element.
Take the three-layer object . Flattening the outer layer first gives the family . Flattening each inner family first gives . One more union gives by either route.
Both algebra-law routes return two, and both monad-associativity routes return the full three-point subset.
The living notebook
Explore the model
Interactive lab · probability
Count subsets while tracking lost structure
Pause and Reset, then set success probability to 0.5 and trials to 3. Predict eight equally likely subsets of a three-point set, grouped by size with counts 1, 3, 3, and 1. The three singleton subsets lie in one bar, although their maxima in the worked chain are 0, 1, and 2. The histogram counts subsets but neither computes their unions nor their algebra interpretations. For fresh comparisons use Pause, Reset, then both controls; parameter changes retain elapsed time.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forAn algebra uses labeled elements and their operation, information that a subset-size histogram does not preserve.
Pause & reason
Check your understanding
Your turn
Try it yourself
For and , list and explicitly. Apply the monad multiplication to each and explain why their difference does not violate a unit law.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
A singleton containing a subset differs from a family containing the singleton subsets of its elements. Count the members of each family before taking unions.
Compare with the solution
The first family is and has one member. The second is and has two members. Union removes the outer layer in each case and gives . The unit laws require equality after multiplication, not equality of the two insertion maps themselves. Both composites are the identity at S.
Keep the idea
Take it with you
- A monad includes natural unit and multiplication maps satisfying three coherence equations.
- The powerset monad is covariant through direct images, with singleton insertion and union.
- An algebra interprets structured data and must respect both singleton insertion and flattening.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.