monads and algebras - an introduction - school of computer ...udr/notes/monads.pdf · 1 algebras of...

26
Monads and Algebras - An Introduction Uday S. Reddy April 27, 1995 1

Upload: lyduong

Post on 15-Feb-2019

216 views

Category:

Documents


0 download

TRANSCRIPT

Monads and Algebras - An Introduction

Uday S. Reddy

April 27, 1995

1

1 Algebras of monads

Consider a simple form of algebra, say, a set with a binary operation. Such an algebra isa pair 〈X, ∗ : X × X → X〉. Morphisms of these algebras preserve the binary operation:f(x ∗ y) = f(x) ∗ f(y).

We first notice that the domain of the operation is determined by a functor F : Set → Set(the diagonal functor FX = X×X). In general, given an endofunctor F : C → C on a categoryC, we can speak of the “algebras” for F , which are pairs 〈X, α : FX → X〉 of an object X ofC and an arrow α : FX → X. Morphism preserve the respective operations, i.e.,

FXFf

- FY

X

α? f

- Y

β?

Now, in algebra, it is commonplace to talk about “derived operators.” Such an operatoris determined by a term made up of variables (over X) and the operations of the algebra.For example, for the simple algebra with a binary operation, terms such as x, x ∗ (y ∗ z), and(x ∗ y) ∗ (z ∗ w) determine derived operators. From a categorical point of view, such derivedoperators are just compositions of the standard operators and identity arrows:

XidX- X

X × (X ×X)idX×α- X ×X

α- X

(X ×X)× (X ×X)α×α- X ×X

α- X

To formalize such derived operators, we think of another functor T : C → C into which wecan embed the domains of all the derived operators. In particular, we should have embeddingsI

.→ T and FT.→ T . If C has colimits, we can just take the initial solution of the recursive

definition:TX = X + FTX (1)

to obtain the functor T . We may think of T is a “closed” functor that includes all possiblecompositions of F ’s and identity functors. For example, for the simple algebra with a binaryoperation, TX is the set of all binary trees over X. We can then define the collection of allderived operators by a map α : TX → X given by the inductive definition α = [id, α ◦ Fα].

We are moving from algebras of functors F towards algebras of “closed” functors T . Soon,we will dispense with functors F altogether and add appropriate structure to the “closed”functors T to form monads. In this setting, it is useful to think of TX as forming an abstractform of “terms” over X. The map α is then viewed as a “valuation” map, which gives valuesto such terms in X.

So far, we have just restated algebras of functors as algebras of “closed” functors. If all wecan say in terms of “closed” functors is a restatement of what we could say in terms of functors,there is not much point to the exercise. Is there something to be gained by going to “closed”functors? Indeed, it becomes apparent as soon as we consider algebras with equational axioms.Let us refine our simple algebras by assuming an associativity axiom for the binary operation:

x ∗ (y ∗ z) = (x ∗ y) ∗ z (2)

As such, the axiom is an equivalence between two derived operators. When we use algebrasof functors, we have to add the axiom explicitly after the fact. On the other hand, when weuse algebras of “closed” functors, we can refine the “closed” functors by taking into account

2

equational axioms such as associativity. For example, instead of taking TX to be the setof binary trees over X, we can take it to be set of binary trees “modulo associativity,” i.e.,(nonempty) lists, over X. T is still a “closed” functor even though it is not freely generated bya functor F . Algebras of the form 〈X, α : TX → X〉 will automatically satisfy the associativitylaw (2) because the domain of α already incorporates associativity.

Let us look more closely at the structure required of “closed” functors. We need two naturaltransformations η : I .→ T and µ : TT .→ T . These transformations need not be embeddingsany more because we expect that our abstract terms will be obtained by identifying manyconcrete terms. The transformation ηX regards an element of X as an abstract term. Thinkof it as a “variable term” pxq. The transformation µX is similar to a substitution operator.It converts an abstract term over abstract terms, say t[u/x] to an abstract term. Write theresulting term as t〈x := u〉. When the “closed” functor is freely generated, as in (2), a variableterm pxq will be just x, and a composite term t〈x := u〉 will be just t[u/x]. But, in themore general context, they can be different. Nevertheless, they must satisfy the usual laws ofsubstitution:

t〈x := pyq〉 = t[y/x]pxq〈x := t〉 = t

t〈x := u〈y := v〉〉 = t〈x := u〉〈y := v〉

It turns out that every term has exactly one “variable” (which could be of an appropriateproduct type to accommodate multiple indeterminates). So, we can dispense with variablenames and use the notation p•q for a variable term, t〈u〉 for a substitution term and t[u] for aterm of terms. In this notation, the laws of substitution should read as:

t〈p•q〉 = tp•q〈t〉 = t

t〈u〈v〉〉 = t〈u〉〈v〉

These considerations lead to the definition of monads:

Definition 1 A monad on a category C is a triple T = 〈T, η, µ〉 of an endofunctor and twonatural transformations as follows:

TT

T

µ?

I

η6

This data must satisfy the following “unit laws” and the “associativity law”

T = TITη

- TT �ηT

IT = T

T

µ?==

====

============

TTTTµ

- TT

TT

µT? µ

- T

µ?

The natural transformations η and µ are called the unit and the multiplication of the monadrespectively.

The algebras for a monad will be pairs 〈X, α : TX → X〉 of objects X and arrows α.Regard TX as a set of abstract terms denoting derived operators, and α as a valuation mapthat assigns values to such terms. These data must satisfy certain axioms too.

3

1. Evaluating a variable term should give back the value of the variable. So, the composite

XηX- TX

α- X

must be the identity.

2. A term obtained by substitution of variables, say, t[u/x] can be evaluated in two ways.We can evaluate u and t in order. Or, we can take the composite term t〈x := u〉 andevaluate it at once. These two evaluations must be equal.

TTXTα- TX

TX

µX? α

- X

α?

A morphism of T -algebras is an arrow h : 〈X,α〉 → 〈Y, β〉 such that

TXTh- TY

X

α? h

- Y

β?

(Note that this is unchanged from algebras of functors.) It is common practice to denote analgebra by its structure map TX

α→ X, because X is implicit in its type. A morphism ofalgebras is denoted by the notation:

TX

X

α?

h-

TY

Y

β?

The category of T -algebras and algbera morphisms is denoted CT and called the Eilenberg-Moore category of T .

A free algebra for T is an algebra of the form 〈TX, µX : TTX → TX〉. The laws of algebras

TXηTX- TTX

TX

µX?

=========

TTTXµTX- TTX

TTX

TµX? µX- TX

µx?

trivially follow from the properties of the monad T . In a set-theoretic context, the elements ofa free algebra are simply the abstract terms obtained from T .

In presenting the category of free T -algebras, one uses a simplification. Note that anymorphism h : 〈TX, µX〉 → 〈TY, µY 〉 is uniquely determined by its “action on X,” viz., ηX ;h :X → TX → TY . Given such an action f : X → TY , we can recover h by h = Tf ;µY :TX → TTY → TY . Thus, in presenting the category of free algebras, we can dispense withthe algebra structure and take arrows to be the arrows (in C) of the form X → TY .

Formally one defines a category CT , called the Kleisli category of T , as follows:

• Objects are the objects X of C, understood as standing for free algebras 〈TX, µX〉.

• Arrows f : X →K Y are the arrows f : X → TY of C, understood as standing formorphisms f∗ = Tf ;µY : 〈TX, µX〉 → 〈TY, µY 〉.

4

The identity arrows are ηX : X → TX and the composition of f : X → TY and g : Y → TZis f ; g∗. The Kleisli category CT is equivalent to the full subcategory of free algebras in CT .

In general, it would appear that Kleisli categories are useful for modelling syntax, i.e., thesurface form of semantic descriptions or programs, as evidenced by [Mog91, Wad92]. On theother hand, Eilenberg-Moore categories play a role in structuring semantics, in particular, thevarious structures used for semantic models.

We give several examples of monads and their algebras:

Example 2 There is a monad list : Set → Set which assigns to each set X the set of lists (orsequences) over X. The unit ηX maps an element x ∈ X to the singleton sequence 〈x〉 and themultiplication µX maps a sequence of sequences 〈s1, . . . , sn〉 to their concatenation s1 · · · sn.

Put another way, an abstract term for the list monad is a formal product of the formx1 · · ·xn. A variable term is just a product of a single variable x. The substitution x1 · · ·xn〈x1 :=s1, . . . , xn := sn〉 is the concatenation s1 · · · sn.

A list-algebra is a pair 〈X, Π : listX → X〉 where Π is a valuation function that assigns toeach formal product x1 · · ·xn a value in X. The laws of list-algebras are then

Π(x) = xΠ(x1 · · ·xn〈x1 := s1, . . . , xn := sn〉) = Π((Πs1) · · · (Πsn))

Writing e for Π〈〉 and x · y for Π〈x, y〉, we obtain the following laws as a consequence of thecorresponding properties for list concatenation:

x · e = x = e · xx · (y · z) = (x · y) · z

Thus, list-algebras are precisely monoids 〈X, ·, e〉 and morphisms are monoid morphisms. Thefree list-algebras are free monoids, i.e., lists with concatenation as the binary operation. TheKleisli category maps are functions of the form X → listY .

One can similarly define a nonempty list monad list+ : Set → Set. The algebras of thismonad are semigroups 〈X, ·〉.

There is a multiset monad Set → Set with singleton multisets as the unit and multisetunion as the multiplication. The following notation is useful in this context. Recall that amultiset over X is a function φ : X → N that is “finitary” in the sense that φ(x) = 0 for allbut finitely many x. The set of such finitary functions is called the “N-span” of X, denotedN〈X〉. It will be convenient to write functions φ as finite formal sums k1x1 + · · ·+ knxn whereki ∈ N and xi ∈ X. (The elements x not listed in the sum are understood to have coefficients0.) In this notation, a singleton multiset is just x regarded as a formal sum and multiset unionis:

k1(∑

i

l1ixi) + · · ·+ kn(∑

i

lnixi) 7→∑

i

(n∑

j=1

kjlji)xi

where, on the right, the outer∑

is fomal and the inner∑

is on naturals. These notations canbe used for all K-span monads where K has addition.

The Z-span monad Z〈−〉 : Set → Set has abelian groups as algebras.

Example 3 Let M = 〈M, ·, e〉 be a monoid. An action of M (on a set) is a pair 〈X, α :X ×M → X〉 such that

α(x, e) = xα(x, ab) = α(α(x, a), b)

A morphism of M -actions f : 〈X,α〉 → 〈Y, β〉 is a function such that

f(α(x, a)) = β(f(x), a)

5

Thus, we have a category M−Act of M -actions.Actions of M can be viewed as automata. M consists of abstract “instruction sequences”

for the automaton and X is its state set. The action α is then a transition function thatspecifies the effect of running an instruction sequence a in a state x.

M -actions can be viewed as algebras of a monad −×M : Set → Set. The unit ηX : X →X ×M of this monad sends x to (x, e) and the multiplication µX : (X ×M) ×M → X ×Msends ((x, a), b) to (x, ab). The unit laws and the associativity law of the monad follow fromthe unit laws and the associativity law of the monoid M .

M -actions are now precisely algebras of this monad.Note that monoid is the minimum structure needed on M to make a monad in this fashion.

Semigroups won’t do, for example. The definitions of monads and monoids on the one hand,and algebras and monoid actions on the other, have a great deal of resemblance. The maindifference is that monoid is a structure on sets while a monad is a structure on functors.

If R is a ring, we can define a monad R ⊗ − : Ab → Ab with unit x 7→ 1 ⊗ x andmultiplication r1 ⊗ (r2 ⊗ x) 7→ r1r2 ⊗ x. The algebras of this monad are left R-modules.

Example 4 Consider the finite powerset monad F : Set → Set where FX is the set of finitesets over X, the unit ηX sends x ∈ X to a singleton {x} ∈ FX, and the multiplicationµX : FFX → FX is the union operation {a1, . . . , an} 7→ a1 ∪ . . . ∪ an. So, an abstract termof F is a finite set {x1, . . . , xn}. A variable term is a singleton set and abstract substitution{x1, . . . , xn}〈x1 := a1, . . . , xn := an〉 is the union a1 ∪ · · · ∪ an.

If 〈X, α : FX → X〉 is an algebra for this monad, write ⊥ for α(∅) and x ∨ y for α{x, y}.From the properties of finite sets, it follows that ∨ is associative, commutative, idempotent andhas ⊥ is the unit. Thus, algebras of F are pointed semilattices 〈X,∨X ,⊥X〉.

Defining x ≤ y ⇐⇒ x∨ y = y, one verifies that ≤ is a partial order. The element ⊥ is theleast element in this partial order and ∨ is the join operation.

Similarly, the nonempty finite powerset monad F+ : Set → Set gives rise to semilattices(with possibly no bottom elements).

Example 5 The powerset monad P : Set → Set is defined similarly, with the unit givingsingletons and the multiplication giving unions.

The algebras of this monad are of the form 〈X,∨

X : PX → X〉 where the operation∨

assigns to every subset a ⊆ X, an element of∨a ∈ X. Reasoning as above, we can define

a partial order x ≤ y ⇐⇒∨{x, y} = y and notice that

∨is the supremum operation with

respect to this order. Thus, the algebras of the powerset monad are complete semilattices. Themorphisms are sup-preserving functions, also called additive functions. (Complete semilatticesare also complete lattices, but their morphisms preserve only sups.)

The free algebras of the powerset monad are of the form 〈PX,⋃〉. They are complete

lattices, but have additional structure: they are atomic and form boolean algebras. One callsthem complete atomic boolean algebras (CABAs). However, the morphisms of P-algebras donot preserve this additional structure.

The Kleisli maps f : X →K Y are functions f : X → PY . Any such function f is essentiallya binary relation between X and Y . Thus, the Kleisli category SetP is isomorphic to Rel, thecategory of sets and relations.

Example 6 The subsingletons monad P1 : Set → Set assigns to a set X the set of subsets ofX containing at most one element. Thus, an element of P1X is either ∅ or a singleton {x}.The unit is ηX(x) = {x} and the multiplication is µX(∅) = µX{∅} = ∅, µX{{x}} = {x}. Allthis is just a specialization of what was said above for the powerset monad.

Equivalently, this monad may be viewed as the lift monad (−)⊥ : Set → Set which simplyadds an additional element ⊥ = ∅ to a given set X.

6

The algebras for this monad are pairs 〈X, α : X⊥ → X〉. Given that α(x) must be x for allx ∈ X, all that is left to be specified is α(⊥). Thus, the algebras are pointed sets, i.e., sets Xwith distinguished points ⊥X . The morhpisms preserve these points (called strict functions).Incidentally, the free algebras are also pointed sets. So, the Kleisli category is equivalent to theEilenberg-Moore category.

The Kleisli maps f : X →K Y are functions f : X → Y⊥ which are essentially partialfunctions f : X → Y . Thus, the Kleisli category is equivalent to Pfn, the category of sets andpartial functions.

Example 7 The category Poset has posets for objects and monotone functions for morphisms.Consider the functor P : Poset → Poset that assigns to a poset X the poset of all downward-closed subsets (downsets) of X, ordered by inclusion. This functor can be extended to a monadby associating the unit η : x 7→ ↓{x} (where ↓a = { z ∈ X : ∃x ∈ a. z ≤ x }) and themultiplication µ : a 7→

⋃a. This is called the downsets monad on Poset.

The algebras of this monad are of the form 〈X,∨

X : PX → X〉 which are again completesemilattices. To see that

∨X is a supremum operation, consider

∨X a. If x ∈ a then ↓{x} ⊆ ↓a

which implies x ≤∨

X a. If z is an upper bound of a, then ↓a ⊆ ↓{z}. So,∨

X a ⊆ z. Thus,complete semilattices can be viewed as algebras in two different ways.

The free algebras are of the form 〈PX,⋃〉. These are complete lattices, but have additional

structure. They are prime-algebraic with complete primes of the form ↓{x} for x ∈ X. (Notethat, for every a ∈ PX, a =

⋃{ ↓{x} : x ∈ a }.)

The Kleisli maps X → PY can be characterized as relations F ⊆ X × Y satisfying:

x′ ≥X x ∧ xF y ∧ y ≥Y y′ =⇒ x′ F y′

Other similar examples include

• the finite lower set monad F : Poset → Poset whose algebras are pointed join-semilattices,

• the nonempty finite lower set monad F+ : Poset → Poset whose algebras are join-semilattices, and

• the subsingleton lower set monad F1 : Poset → Poset whose algebras are pointed posets(posets with least elements).

In each case, the algebra maps preserve the stated structure (strict semilattice morphisms,semilattice morphisms, strict monotone functions respectively).

At this point, it is useful to relate various notions of “algebraicity” for complete semilatticesor, more generally, for complete partial orders (cpo’s). Let X be a cpo.

1. A compact element in X is an element k ∈ X such that for all directed sets a ⊆ X,k ≤

∨a implies k ≤ x for some x ∈ a. X is an algebraic cpo if every element x ∈ X is

the lub of the compact elements below it.

2. A complete prime in X is an element k ∈ X such that whenever k ≤∨a (for any a with

a lub), k ≤ x for some x ∈ a. X is said to be prime-algebraic if every element x ∈ X isthe lub of the complete primes below it.

3. If X is a pointed cpo with a least element ⊥X , an atom of X is a complete prime k thatcovers ⊥X , i.e., k 6= ⊥X and x ≤ k =⇒ x = ⊥X ∨x = k. X is said to be atomic if everyelement is the lub of atoms below it.

7

Evidently, atoms are complete primes which are in turn compact elements. So, there are properinclusions between atomic cpos, prime-algebraic cpos and algebraic cpos.

Example 8 Consider the functor D : Poset → Poset that assigns to a partial order X theposet of all directed downsets (also called ideals) over X, ordered by inclusion. The unit ηX

sends x to the principal ideal ↓{x} = { y : y ≤ x } and the multiplication µX sends a directeddown-closed family a of ideals to its union. It may be verified that these data give a monad.

The algebras for the directed sets monad are complete partial orders or cpo’s (not necessarilypointed). They are posets X with an operation

∨↑ : DX → X for lubs of directed downsets.The morphisms preserve directed sups (called Scott-continuous functions).

The free algebras for the directed sets monad are of the form 〈D(X),⋃↑〉. They are ideal

completions of posets or, equivalently, algebraic cpo’s. (“Domains” are algebraic cpo’s with acountable basis.)

The Kleisli maps X →K Y are monotone functions X → DY for posets X and Y . Suchmaps are called approximable maps and characterized as relations F ⊆ X × Y satisfying thefollowing conditions:

1. For all x ∈ X, there is y ∈ Y such that xF y.

2. If x′ ≥ x, xF y and y ≥ y′ then x′ F y′.

3. If xF y1 and xF y2, there exists y ≥ y1, y2 such that xF y.

In place of directed sets, one can use various kinds of subsets which, after adding downward-closure, give rise to monads. Here are some examples:

Subset system Condition on a subset a ⊆ X Algebrasω-chains a linearly ordered ω-cposbounded sets a has an upper bound bounded complete cposconsistent sets every finite a′ ⊆ a has an upper bound consistently complete cpospairwise consistent sets every pair in a has an upper bound coherent cpos

The morphisms in each case preserve the lubs of appropriate subsets. (They are not merelyScott-continuous.) More on the structure of subset systems may be found in [Mes83].

Example 9 A web A = (|A|, _A) is a set with a reflexive-symmetric binary relation called“coherence.” The morphisms of webs preserve this relation, i.e., x _ y =⇒ f(x) _ f(y).This gives a category Web.

Define a functor Pcoh : Web → Web which assigns to a web A the set of pairwise coherentsubsets of |A| (or, simply, coherent sets of A). The coherence relation for PcohA is

a1_ a2 ⇐⇒ a1 ∪ a2 ∈ PcohA ⇐⇒ ∀x ∈ a1.∀y ∈ a2. x _A y

This functor gets the structure of a monad by adding the unit of singletons and the multipli-cation of coherent unions. Thus, we obtain the coherent sets monad on webs.

The free algebras of Pcoh are easy to recognize. They are of the form 〈PcohA,⋃coh〉 and

are called coherent spaces. They are partially ordered by inclusion and form coherent cpos. Inaddition, they have the property of being atomic. A morphism of coherent spaces is determinedby a web map f : A→ PcohB or, equivalently, a relation F ⊆ |A|×|B| that preserves coherence.

A partially ordered web, or poweb, is a pair (|A|, _A) where |A| is a poset 〈|A|,≤A〉. Thisis subject to the axiom:

x′ ≤ x _ y ≥ y′ =⇒ x′ _ y′

8

In particular, note that x ≤ y implies x _ y. Such ordered webs are also called prime eventstructures. The morphisms of powebs are monotone coherence-preserving functions. This givesa category Poweb.

The coherent downsets monad ˆPcoh : Poweb → Poweb assigns to a poweb A the set ofcoherent downsets of A, ordered by inclusion. The coherence relation for ˆPcohA is as for websabove.

The algebras of ˆPcoh are powebs (|A|, _A) equipped with an operation∨

A : ˆPcohA → A(which is a morphism of powebs). Now, we claim

x _ y ⇐⇒ x ↑ y

If x _ y then∨{x, y} exists. So, x ↑ y. Conversely, if x ↑ y then there is some z such that

x ≤ z and z ≥ y, and the condition of powebs implies that x _ y. The algebras of ˆPcoh arecoherent cpos, i.e., posets where all pairwise consistent sets have lubs.

The free algebras of ˆPcoh are of the form 〈 ˆPcohA,⋃coh〉. They are prime-algebraic coherent

cpo’s, i.e., coherent cpo’s where every element x is the lub of the complete primes below x.The Kleisli maps A →K B between powebs are characterized as relations F ⊆ |A| × |B|

satisfying the following conditions:

1. x1_ x2, x1 F y1 and x2 F y2 implies y1

_ y2.

2. x′ ≥ x, xF y and y ≥ y′ implies x′ F y′.

Example 10 A consistency structure on a set |A| is a family of finite subsets ΓA such that

1. x ∈ A implies {x} ∈ ΓA, and

2. a ∈ ΓA and a′ ⊆ a implies a′ ∈ ΓA.

Note that consistency structures generalize webs by moving from binary relations to “multiary”relations. A morphism of consistency structures are functions f : A → B such that a ∈ ΓA

implies f [a] = { f(x) : x ∈ a } ∈ ΓB. Thus, we have a category Con.A subet a ⊆ |A| is said to be consistent if all its finite subsets are in ΓA. Let PconA denote

the set of all consistent sets of A. We can associate a consistency structure with PconA bydefining Γ to be set of finite sets {a1, . . . , an} such that a1 ∪ · · · ∪ an is a consistent set. Wehave a functor Pcon : Con → Con which extends to a monad.

The free algebras of this monad, of the form 〈 ˆPconA,⋃con〉, are called qualitative domains.

They are atomic, consistently complete cpos.A partially ordered consistency structure is a pair (|A|,ΓA), where |A| is a poset, such that

a ∪ {x} ∈ ΓA ∧ x ≥ x′ =⇒ a ∪ {x, y} ∈ ΓA

Such structures are also called prime information systems. The morphisms are monotoneconsistency-preserving functions. This gives a category Pocon.

There is a consistent downsets monad ˆPcon : Pocon → Pocon. Its algebras are partiallyordered consistency structures (|A|,ΓA) equipped with an operation

∨con : ˆPconA→ A. As forcoherent downsets above, it is possible to argue that, for all finite sets a ⊆ |A|,

a ∈ ΓA ⇐⇒ a ↑

Hence, the algebras are precisely consistently complete cpo’s. The free algebras are prime-algebraic, consistently complete cpo’s.

9

Example 11 The category Preord has objects preordered sets X = 〈X,<∼X〉 and morphisms

monotone functions. Given a preordered set X, define an equivalence relation ≈X by x ≈y ⇐⇒ x <∼ y ∧ y <∼ x. The quotient X/≈X is a partial order.

This gives a monad T : Preord → Preord with TX = X/≈X . Note that TTX ∼= TX.A monad with this property is called an idempotent monad. The unit ηX sends x ∈ X to theequivalence class [x] ∈ X/≈X . The multiplication µX is the isomorphism TTX

∼→ TX.This example is interesting in that the unit η is not an embedding.

The notion of comonads and coalgebras is defined by duality. If C a category, a comonadon C is a triple L = 〈L, ε, δ〉) of an endofunctor and two natural transformations as follows:

LL

L

δ6

I

ε?

This data is subject to the axioms:

L = LI �Lε

LLεL- IL = L

L

δ6

====

====

==========

LLL �Lδ

LL

LL

δL6

�δ

L

δ6

The natural transformations ε and δ are called the counit and comultiplication respectively. Acoalgebra for L is a pair 〈X, α : X → LX〉 such that

X �εX

LX

X

α6

========

LLX �Lα

LX

LX

δX6

�α

X

α6

Morphisms of coalgebras are defined in the expected fashion:

LXLh- LY

X

α6

h- Y

β6

Example 12 Consider the category CSLat of complete semilattices and additive functions.Define a functor P : CSLat → CSLat that assigns to a complete semilattice X the completesemilattice PX of all subsets of X, ordered by inlcusion. The counit εX : PX → X sends asubet a ⊆ X to

∨a. The comultiplication δX : PX → PPX sends a to the set of singletons

{ {x} : x ∈ a }.A coalgebra for P is a pair 〈X α : X → PX〉 of a complete semilattice X and an additive

function α. The counit law for coalgebras means that∨

X α(x) = x. So, α(x) is a set ofapproximations of x. The comultiplication law means that

{ {y} : y ∈ α(x) } = {α(y) : y ∈ α(x) }

Thus, for all y in the image of α, α(y) = {y}. Working this out, one finds that α maps x ∈ Xto the set of atoms below x. Now, the counit law

∨X α(x) = x says precisely that X is a

complete atomic lattice.

10

The morphisms h : 〈X,α〉 → 〈Y, β〉 of coalgebras preserve the atoms, i.e.,

β(h(x)) = {h(a) : a ∈ α(x) }

In particular, if x is an atom, α(x) = {x}. So, h(x) is an atom as well. Thus, h is completelydetermined by its action on the atoms.

Since complete atomic lattices are isomorphic to powersets PX with atoms X, and themorphisms are functions on the atoms, the category of coalgebras is equivalent to Set.

11

2 Monads and adjunctions

The concept of monads is closely related to that of adjunctions, which is at the heart of categorytheory. We examine this connection.

An adjunction is a pair of functors between two categories

CF-

�G

A

together with a natural isomorphism:

φx,a : A(Fx, a) ∼= C(x,Ga) : φ−1x,a (3)

(We are lower case letters for objects: x, y, z for the objects of C and a, b, c for the objectsof A.) In this situation, one writes F a G : A → C and calls F the left adjoint of F and Gthe right adjoint of F . Each functor in the adjunction determines the other uniquely up toisomorphism.

Typically, A is a category of some “structures” over the objects of C. Then, F is the “free”functor that assigns to an object x of C, the free structure over x. The functor G is a “forgetful”functor that assigns to a structure a, the underlying object of a (“forgets” the structure of a).

For instance, consider the adjunction between sets and monoids:

SetF-�G

Mon

where F is the free monoid functor X 7→ 〈listX, ·, ε〉 and G is the underlying set functor〈A, ·A, eA〉 7→ A. We have a natural isomorphism:

φX,A : Mon(FX,A) ∼= Set(X,GA) : φ−1X,A

which means that the set of monoid morphisms FX → A is (naturally) one-to-one with theset of functions X → GA. Let us see the details. Given a function f : X → A, there exists aunique monoid morphism h = φ−1

X,A(f) : 〈listX, ·, ε〉 → 〈A, ·A, eA〉 such that the restriction of hto X is f . It is given by

h〈x1, . . . , xn〉 = f(x1) ·A · · · ·A f(xn)

Note that the composite GF : Set → Set assigns to a set X the set of lists over X (theunderlying set of the free monoid). We know that this functor extends to a monad. Thishappens in general.

Whenever F a G : C → A is an adjunction, the composite functor T = GF : C → C givesa monad on C. Dually, the composite functor L = FG : A → A gives a comonad on A. Thissituation may be pictured as follows:

CF

-�G

A

T = GF

6

L = FG

6

(monad) (comonad)

Let us see the details of this phenomenon. First, recall that there is a notion of a unit of anadjunction. By setting a = Fx in (3), we get a family of arrows

ηx = φx,a(idFx) : x→C GfX

12

where are easily seen to be natural in x. We take this to be the unit of the monad T . Dually,there is a counit for the adjunction obtained by setting x = Ga in (3):

εa = φ−1x,a(idGa) : FGa→A a

We take this to be the counit of the comonad L. For the multiplications and the comultiplica-tions, respectively, of T and L, we define

µ = GεF : GFGF.→ GF

δ = FηG : FGFG.→ FG

These data do give monads and comonads . . .It is reported that Huber [Hub61] proved this result because “he was having so much trouble

demonstrating that the associative identity was saaisfied” and noticed that all his monadswere associated with adjunctions. Indeed, it simplifies our work considerably to look for anadjunction that induces a monad to obtain the relevant data of the monad. The followingexample would be quite tricky to do without the use of adjunctions.

Example 13 A meet-semilattice is a pair 〈A,∧A〉 where ∧A is a meet operation (associative,commutative and idempotent binary operation). The morprisms preserve meets. This gives acategory MSLat. We claim that there is an adjunction between posets and meet-semilattices

PosetF-�G

MSLat. This means there is a natural isomorphism:

φX,A : MSLat(FX, 〈A,∧A〉) ∼= Poset(X,G〈A,∧A〉)

Take G to be the forgetful functor that maps 〈A,∧A〉 to the underlying poset 〈A,≤A〉. Thepartial order of A is defined by x ≤A y ⇐⇒ x ∧A y = x. For the free functor F , define theupper set of a ⊆ X by ↑Xa = { z ∈ X : ∃x ∈ a. z ≥X x }. Then, we can take FX to be themeet-semilattice 〈F+X,

⋃〉 where F+X is the set of upper sets of nonempty finite subsets of

X. Note that the union of upper sets is an upper set. The induced partial order on F+X isreverse inclusion, ⊇.

The natural isomorphism φ maps a meet-semilattice homomorphism h : 〈F+X,⋃〉 →

(A,∧A) to its restriction f : X → A given by f(x) = h(↑{x}). Note that f is monotone:x ≤ y =⇒ ↑{x} ⊇ ↑{y} =⇒ h(↑{x}) ≤ h(↑{y}). Any such function f uniquely extends to ahomomorphism h(↑a) =

∧{ f(x) : x ∈ a }.

The adjunction induces a monad on Poset, the nonempty finite upper set monad F+ :〈X,≤X〉 7→ 〈F+X,⊇〉. We obtain the relevant data from the adjunction. The unit ηX : X →F+X is φ(idFX). It is given by

ηX(x) = id(↑{x}) = ↑{x}

The counit of the adjunction εA : 〈F+GA,∪〉 → A is φ−1(idGA). It is given by

εA(↑a) =∧A

{ idGA(x) : x ∈ a } =∧A

a

So, the multiplication of the monad µX : F+F+X → X is GεFX . Since F+X is ordered byreverse inclusion, an upper set of a finite set s is as actually downset. Denote it by ⇓s = { a :∃a′ ∈ s. a ⊆ s }. Then µX(⇓s) =

⋃s. This completes the definition of the F+ monad. Note

that the algebras of this monad are precisely meet-semilattices.Other similar examples include

13

• the subsingleton upper set monad F1 whose algebras are “topped” posets (posets withtop elements),

• the finite upper set monad F whose algebras are “topped” meet-semilattices

• the upset monad P whose algebras are inf-complete semilattices.

We see that the intuitive picture given at the beginning of this section is needlessly one-sided.Not only may we regard the objects of A as “structures” over the objects of C, but we mayalso regard the objects of C as “co-structures” over the objects of A. By “co-structure” here,we man the structure of coalgebras with respect to the comonad L.

For the case of the set-monoid adjunction this means that sets are obtainable by adding“co-structure” to monoids. Let us see how. Call a monoid A = 〈A, ·A, eA〉 atomic if there isa subset K ⊆ A such that every x ∈ A can be written uniquely as a product x = k1 · · · kn

of elements in K. (The elements of K are the atoms of A.) A morphism of atomic monoidsh : 〈A,K〉 → 〈B,L〉 is a morphism of monoids such that, whenever x = k1 · · · kn is an atomicfactorization in A, h(x) = h(k1) · · ·h(kn) is an atomic factorization in B. It is clear thatatomic monoids 〈A,K〉 are essentially free monoids generated by K and that atomic monoidmorphisms are essentially functions between the sets of atoms. The category of atomic monoidsis equivalent to Set which is obtained by adding “co-structure” to monoids.

Now, consider the comonad L = FG : Mon → Mon. It assigns to each monoid A themonoid listA. The counit εA : listA → A is just multiplication 〈x1, . . . , xn〉 7→ x1 · · ·xn.The comultiplication δA : listA → list listA maps a list 〈x1, . . . , xn〉 to the list of singletons〈〈x1〉, . . . , 〈xn〉〉. Coalgebras of this comonad are pairs 〈A, α : A → listA〉 of monoids A andstructure maps α. It may be verified that they are precisely atomic monoids with α mappingeach element x ∈ A to the lists of its atomic factors.

The situation we found here is rather special. We started with an adjunction SetF-

�G

Mon

and found an induced monad T = GF on Set and an induced comonad L = FG on Mon.

• From T , we can form a category of algebras SetT which turned out to be equivalent toMon. In this situation, we say that the adjunction is “monadic.”

• From L, we can form a category of coalgebras MonL which turned out to be equivalentto Set. In this situation, we say that the adjunction is “comonadic.”

If an adjunction is both monadic and comonadic, we say it is “bimonadic.”The adjunction between sets and complete semilattices

SetF-�G

CSLat

is also bimonadic. The induced monad on Set is the powerset monad P (Example 5). Theinduced comonad on CSLat is the powerlattice comonad (Example 12). The algebras of thepowerset monad are precisely complete semilattices, and the coalgebras of the powerlatticecomonad on CSLat are complete atomic semilattices which form a category equivalent to Set.

The co-Kleisli categories of such induced comonads are extremely interesting, and foundthroughout programming language theory. For example, the co-Kleisli category of the power-lattice comonad has objects complete lattices and morphisms additive functions of the formf : PA → B. Since additive functions preserve unions in PA, f is uniquely determined byits action on singletons. The action on singletons can be desribed by a function f : A → B.

14

So, the co-Kleisli category is the category of complete lattices with all functions as arrows.Similarly, the co-Kleisli category of the list comonad on Mon is the category of monoids withall functions as arrows.

The following example gives several applications of this feature in semantics.

Example 14 There is an adjunction

CpoF-

�G

Cpo⊥

between the category of cpo’s and continuous functions and that of pointed cpo’s and strictcontinuous functions. (A pointed cpo is a cpo with a least element ⊥.) If X = 〈X,

∨↑X〉 is a cpo,

let X⊥ denote the lifted cpo with an additional least element ⊥. The functor F : Cpo → Cpo⊥assigns to each cpo X the pointed cpo 〈X⊥,⊥〉 obtained by lifting. To each continuous functionf : X → Y it assigns the evident strict extension f⊥ : 〈X⊥,⊥〉 → 〈Y⊥,⊥〉. The functor G givesthe underlying cpo of a pointed cpo.

The monad induced by the adjunction is lifting (−)⊥ : Cpo → Cpo⊥ with unit andmultiplication given by . . . Evidently, the algebras of the monad are precisely pointed cpo’swith strict continuous functions as morphisms.

The comonad induced by the adjunction is also lifting (−)⊥ : Cpo⊥ → Cpo⊥ whichsends a pointed cpo 〈A,⊥A〉 to 〈A⊥,⊥〉. The counit and the comultiplication are given by. . . A coalgebra of this comonad is a pointed cpo 〈A,⊥A〉 equipped with a structure map α :〈A,⊥A〉 → 〈A⊥,⊥〉 which just “picks out” the bottom element ⊥A. A morphism of coalgebras ispreserves the operation of “picking out” the bottom elements, i.e., it is a ⊥-reflecting function.Such morphisms are essentially continuous functions between cpos A \ {⊥A} → B \ {⊥B}. So,the adjunction between cpos and pointed cpos is “bimonadic.”

The co-Kleisli category of the comonad has maps, strict continous functions A⊥ → Bbetween pointed cpo’s. Since the least element ofA⊥ is always mapped to⊥B, this is determinedby a continous function A→ B. Thus, the co-Kleisli category has pointed cpo’s for objects butall continous functions for morphisms. We often use the symbol ! for such a comonad when theco-Kleisli category is cartesian closed (with inspiration from linear logic).

Many other structures over Cpo have such ! comonads. The category of coherent cposCohCpo has objects coherent cpos (i.e., cpo’s where pairwise compatible subsets have lubs).The morphisms are additive functions that preserve the lubs of pairwise compatible subsets.The adjunction between Cpo and CohCpo gives rise to a comonad ! on CohCpo whoseco-Kleisli category has coherent cpo’s but all continuous functions. The category of bounded-complete cpos BcCpo similarly has a ! comonad whose co-Kleisli category has all continuousfunctions between bounded-complete cpo’s.

15

3 Monad morphisms

If S and T are monads on C, a morphism of monads σ : S → T is a natural transformationS

.→ T that commutes with the units and multiplications in the evident fashion:

SSσσ- TT

S

µS

? σ- T

µT

?

I

ηS6

= I

ηT6

We call σ a monomorphism (epimorphism) of monads if each component σX is a mono (epi).The notions of submonads and quotient monads are defined correspondingly.

In set-theoretic terms, S and T generate sets of abstract terms. A morphism σ : S → T thenmaps S-terms to T -terms in such a way that variable terms and substitutions are preserved.For example, there is a monad morphism F+ → F (in fact, a monomorphism) that injectsnonempty finite sets F+X to finite sets FX. So, F+ is a submonad of F. There is a monadmorphism list → F (in fact, an epimorphism) that maps lists listX to finite sets of their elementsFX. So, F is a quotient monad of list.

If σ : S → T is a morphism of monads, it induces a functor Cσ : CT → CS between thecorresponding categories of algebras. (Note the reversal of direction.) Cσ assigns to a T -algebraα : TX → X the S-algebra σX ;α : SX → TX → X. Its morphism part assigns to a morphismf : 〈X,α〉 → 〈Y, β〉 of T -algebras, the same function f regarded as a morphism of S-algebras.That f is indeed a morphism of S-algebras is evidenced by

SXSf

- SY

TX

σX? Tf

- TY

σY?

X

α? f

- Y

β?

where the top square is an instance of naturality and the bottom square commutes because fis a morphism of T -algebras. At the level of categories, this situation is depicted by:

CT Cσ- CS

C

GT

?= C

GS

?

For example, if σ : F+ → F is the injection then Cσ : CF → CF+is the forgetful functor that

forgets the bottom elements of semilattices. For σ : list → F, the induced functor Cσ : CF →C list is the inclusion of semilattices in Mon.

More interestingly, functors of this form are all induced by monad morphisms. Moreprecisely, if G : CT → CS is a functor such that

CT G- CS

C

GT

?= C

GS

?

16

then G = Cσ for a monad morphism σ : S → T . To recover σ from G, consider the action ofG on the free algebra µT

X : TTX → TX. The image of µTX is an S-algebra structure on TX

(since G preserves the underlying objects). Denote it by µTX : STX → TX.

Since G also preserves the underlying arrows of morphisms, we have

G :

TTX

TX

µTX

?

Tf-

TTY

TY

µTY

?

7→

STX

TX

µTX

?

Tf-

STY

TY

µTY

?

for all morphisms h. Now, for any arrow f : X → Y in C, Tf : TX → TY is a morphism ofT -algebras. So, by setting h = Tf , we find the commutative square:

STXSTf

- STY

TX

µTX

? Tf- TY

µTY

?

which just says that µT : ST .→ T is a natural transformation.Define σ = SηT ; µT : S .→ ST

.→ T . A little diagram chasing shows that it is a monadmorphism. Now, Cσ〈X,α〉 = 〈X, σX ;α〉. . . .

Example 15 Let A and B monoids, with induced free action monads −×A, −×B : Set →Set. Monad morphisms − × A → − × B are of the form − × h : − × A → − × B whereh : A→ B is a morphism of monoids. Any such morphism induces a functor from B-actions toA-actions, viz., h−Act = Set−×h : B−Act → A−Act defined by h−Act(β : X × B → B) =(α : X ×A→ A) where α(x, a) = β(x, h(a)).

Thinking of β is an automaton with instruction sequences B, h−Act(β) simulates an A-automaton using β by translating every A-instruction sequence a to h(a).

Example 16 The monomorphism σ : F+ → F induces a functor Setσ : SLat• → SLat whichjust forgets the least elements of pointed semilattices. Similarly, F is a submonad of P, D is asubmonad of P etc. The induced functors are forgetful. More interestingly, the list monad andthe free abelian group monad Z〈−〉 are both submonads of the free ring monad. The inducedfunctors forget part of the structure of a ring.

The epimorphism σ : list → Fin induces a functor Setσ : SLat• → Mon which regardsa pointed semilattice as a monoid (there by ignoring the fact that ∨ is commutative andidempotent).

17

4 Distributive laws and composite monads

Suppose we are given two monads S, T : C → C. Does their composite TS : C → C forma monad? Treating this entirely formally, we need a unit η : I .→ TS and a multiplicationµ : TSTS .→ TS. The unit can be defined as the composite η = ηT ηS : I .→ TS. However,there is no immediate way to define multiplication. The composition µTµS : TTSS .→ TS hasthe source TTSS which does not match the required TSTS. But, all is not lost. If we havea natural transformation λ : ST .→ TS, we can complete the definition of µ as TλS;µTµS :TSTS

.→ TTSS.→ TS. The natural transformation λ (with a suitable axiomatization) is called

a “distributive law” for S over T . Conversely, if TS is indeed a monad with a multiplicationµ : TSTS .→ TS, we can produce a distributive law λ : ST .→ TS by the composition

ST = ISTIηT STηS

- TSTSµ- TS

To get some intuition for this notion, treat S and T as assigning to a set X two collectionsof terms SX and TX. The set TSX then contains terms formed from T with subterms formedfrom S. Regard T -terms as formal “summations”

∑i xi and S-terms as formal “products”∏

j yj . A TS-term is then a sum-of-products∑

i

∏j xij . A “distributive law” transforms a

product-of-sums term to a sum-of-products term as in∏i∈I

∑j∈J(i)

xij −→∑

f∈ΠJ

∏i∈I

xi f(i) (4)

where ΠJ stands for the set of “dependent” functions mapping indices i ∈ I to indices j ∈ J(i).The “distributive law” (better called a “distribution operator”) distributes multiplication overaddition. For example, the term (x1 + x2) · (y1 + y2) gets mapped to the term x1y1 + x1y2 +x2y1 +x2y2. The laws associated with the distribution operator will ensure that the two termsare evaluated in the same way.

To motivate these laws, we use the term notation of Section 1 and assume a distributionoperator λ that converts an ST -term of the form s[t] to a TS-term of the form t′[s′]. We writethis as λ : s[t] 7→ t′[s′]. (There does not seem to be a way to represent this operator implicitlyin the syntax.) We need to specify what happens if s or t is a variable term or a substitutionterm:

λ : s[p•q] 7→ p•q[s] λ : p•q[t] 7→ t[p•q]

λ : s[t1] 7→ t′1[s′] λ : s′[t2] 7→ t′2[s

′′]

λ : s[t1〈t2〉] 7→ t′1〈t′2〉[s′′]

λ : s2[t] 7→ t′[s′2] λ : s1[t′] 7→ t′′[s′1]

λ : s1〈s2〉[t] 7→ t′′[s′1〈s′2〉]The first two rules say that the action of λ on variable terms is null. The next two rules saythat distribution commutes with substitution.

The following is a categorical statement of these ideas:

Definition 17 If S = 〈S, ηS , µS〉 and T = 〈T, ηT , µT 〉 are monads on a category C, a distribu-tive law of S over T is a natural transformation λ : ST .→ TS such that

S

STλ

-�Sη

T

TS

η TS-

T

STλ

-�ηS T

TS

Tη S

-

STTλT

- TSTTλ

- TTS

ST

SµT

? λ- TS

µTS?

SSTSλ

- STSλS

- TSS

ST

µST? λ

- TS

TµS

?

18

Lemma 18 If S and T are monads on C with a distrbutive law λ : ST .→ TS, then the functorTS : C → C extends to a composite monad (TS)λ with unit and multiplication given by

η = ηT ηS : I = II → TSµ = TλS;µTµS : TSTS → TTSS → TS

The proof is a straightforward diagram chasing. Note that ηT ηS refers to one of the two equalcomposites:

S

IηT ηS

-

ηS -

TS

η TS-

TTηS

-

η T -

Likewise for µTµS .The natural transformations ηTS : S .→ TS and TηS : T .→ TS above are monad

morphisms. The relevant diagrams are:

SSηTSηTS

- TSTS

S

µS

? ηTS- TS

µ?

I

ηS6

= I

η6

TTTηSTηS

- TSTS

T

µT

? TηS- TS

µ?

I

ηT6

= I

η6

This fact will prove important when we consider algebras of composite monads.

Proposition 19 Suppose S, T and TS are monads on C such that

1. η = ηT ηS,

2. ηTS : S → TS and TηS : T → TS are monad morphisms, and

3. the “middle unitary law”

TSTηSηTS

- TSTS

TS

µ?

=============

holds,

then the composite

λ = STηT STηS

- TSTSµ- TS

is a distributive law.

Example 20 Consider the monads P1, list+ : Set → Set. In this example, we write P1X asXε = {ε} + X. The composite functor P1list+ : Set → Set is isomorphic to list : Set → Set

19

which extends to a monad. So, one would expect to find a distributive law λX : list+P1X →P1list+X. It is given by

〈ε〉 7→ ε〈x1, . . . , xn〉 7→ 〈xi1 , . . . , xik〉

where xi1 , . . . , xik is the sequence of non-ε elements of 〈x1, . . . , xn〉.Put another way, think of list+X as the infinite coproduct X + X2 + X3 + · · · . Then

list+(P1X) is

(1 +X) + (1 +X)2 + (1 +X)3 + · · ·= 1 +X + 1 +X +X +X2 + 1 +X +X +X +X2 +X2 +X2 +X3 + · · ·

while P1(list+(X)) is 1 +X +X2 +X3 + · · · . The distrbutive law λX sends each summand ofthe source space to the same summand in the target space.

The induced monad morphisms P1 → list and list+ → list are evident monics. Thecorresponding functors Mon → Set⊥ and Mon → SGrp are forgetful.

Example 21 Consider the monads F1 and F+ on Set, whose algebras are pointed sets andsemilattices respectively. The functor composition F1F+ : Set → Set is isomorphic to F :Set → Set which extends to a monad. The distributive law λX : F+F1X → F1F+X is givenby

{∅} 7→ ∅a 6= {∅} 7→ {{x : {x} ∈ a }}

The same arguments apply to the comosition P1P+ : Set → Set which forms a monadisomorphic to the powerset monad P on Set.

20

Suppose α : TSX → X is a TS-algebra. Since we have monad morphisms S .→ TS andT

.→ TS, X has both a T -algebra structure and an S-algebra structure (which we denote byαT and αS respectively):

SXηT

SX- TSX �TηS

X TX

X

α?� α

Tα S -(5)

In other words, from the valuation map for TS-terms, we can extract a valuation map αS forS-terms and another αT for T -terms.

One would expect that these two evaluation maps compose to give back the original map:

TX

TSXα

-

TαS -

X

α T

- (6)

This is indeed the case as may be verified by diagram chasing. That is, given a TS-term(a T -term with S-subterms), its evaluation by α can be decomposed into the evaluation ofS-subterms followed by the evaluation of the T -term.

Moreover, αS is “λ-distributive” over αT :

STXλX - TSX

SX

SαT

?TX

TαS

?

X� α

Tα S -

(7)

For example, if λ is the distribution operator (4) of products over sums, this says that the inner-most evaluations of

∏i∈I

∑j∈J(i) xij and

∑f∈ΠJ

∏i∈I xi f(i) must be equal. This corresponds

to the usual distributivity law:

(x1 + x2) · (y1 + y2) = x1y1 + x1y2 + x2y1 + x2y2

of multiplication over addition in rings. Another way to think about this identity is thatmultiplication is a homomorphism over addition (in both positions; so it is a “bimorphism”).

Proposition 22 Let T be S monads on C with a distributive law λ : ST .→ TS. If TSX α−→ X

is an algebra for a composite monad TS, then SXαS

−→ X and TXαT

−→ X defined by (5) are

algebra structures on X that satisfy (6) and (7). Conversely, if SX αS

−→ X and TX αT

−→ X arealgebra structures on X satisfying (7), then TSX

α−→ X defined by (6) is an algebra of thecomposite monad.

The algebras of composite monads may thus be called “distributive algebras.” We giveseveral examples of such algebras below.

Example 23 Consider the monads F, D on Poset. The composition of the functors DF :Poset → Poset is isomorphic to P : Poset → Poset. The isomorphism σX : PX ∼→ DFX is:

↓a 7→ ⇓{ ↓a′ : a′ ⊆fin a }

21

with the inverse being directed union. This isomorphism corresponds to the fact a cpo is acomplete lattice if and only if it has finite joins.

There is a distributive law λX : FDX → DFX given by

⇓{↓d1, . . . , ↓dn} 7→ ⇓{ ↓{x1, . . . , xn} : x1 ∈ d1, . . . , xn ∈ dn }

. . .

Example 24 Consider the monads F, F on Poset, whose algebras are (pointed) join-semilatticesand (topped) meet-semilattices respectively. We have a distributive law λX : F FX → F FXgiven by

⇑{↓a1, . . . , ↓an} 7→ ⇑{ ↑{x1, . . . , xn} : x1 ∈ a1, . . . , xn ∈ an }

The upper set of {↓a1, . . . , ↓an} is closure under supersets (denoted by ⇑). On the right, FX isordered by reverse inclusion. So, a lower set by this order is also closure under supersets. Thisgives rise to a composite monad FF. The unit ηX : X → FFX is x 7→ ⇑{↓{x}}.

We claim that the algebras for the composite monad F F are distributive lattices (with units).If α : F FX → X is an algebra, the structure map can be decomposed into αF : FX → X andαF : FX → X, which correspond to finite joins and finite meets respectively (Examples 7 and13). We can then recover α as αF ◦ FαF whose action may be written as

⇑ {↑a1, . . . , ↑an} 7→ ↓ {∧a1, . . . ,

∧an} 7→

∨{∧a1, . . . ,

∧an}

The distributive law gives the identity:

(∨a1) ∧ · · · ∧ (

∨an) =

∨{x1 ∧ · · · ∧ xn : x1 ∈ a1, . . . , xn ∈ an }

Since the operations are finitary, we can reduce it to each of the following equivlanet forms:

z ∧ (∨a) =

∨{ z ∧ x : x ∈ a }

z ∧ (x ∨ y) = (z ∧ x) ∨ (z ∧ y)

To see that α is a lattice, we must also check the absorption laws: x∧ (x∨ y) = x and its dual.Note that x ∧ (x ∨ y) is the valuation of the “term” ⇑{↓{x}, ↓{x, y}}. Since ↓{x} ⊆ ↓{x, y},this term is equal to ⇑{↓{x}}, whose valuation is just x. The other absorption law is similar.

Other similar examples are the following:

• By symmetry, there is a distributive law λ′X : FFX .→ FFX which gives a compositemonad FF. This monad is isomorphic to the above composite monad. The distrbutivelaws λ and λ′ are inverses.

• The distributive law λX : F+F+X.→ F+F+X gives a composite monad F+F+. Its

algebras are distributive lattices (with possibly no units).

• The distributive law λX : F+PX .→ PF+ gives a composite monad PF+. Its algebras arecomplete lattices with an infinite distributive law:

z ∧ (∨a) =

∨{ z ∧ x : x ∈ a }

Such structures are referred to as frames or complete Heyting algebras. The framemorphisms preserve sups and binary meets. As we have already noted the monadisomorphism P ∼= DF, the free frame monad is a composite of three monads DFF+.

22

• The monads ˆPcon and ˇFcon+ on Poset are defined as above but restrict to consistent sets

or finite sets. The distributive law λX : ˇFcon+ ˆPconX → ˆPcon

ˇFcon+X gives a composite

monad ˆPconˇFcon

+. Its algebras are distributive consistently-complete cpo’s. They satisfythe infinite distributive law:

z ∧ (∨cona) =

∨con{ z ∧ x : x ∈ a } if {z} ∪ a is consistent

This is again a composite of three monads D ˆFconˇFcon

+. One can also use pairwisecompatible sets in place of consistent sets above. Bounded sets can also be used, exceptthat

Example 25 If X is a poset, let PpcX denote the poset of pairwise compatible subsets (finitesubsets) of X, ordered by inclusion. We have the usual adaptions. ⇓PpcX is the poset of lowersets of elements of PpcX. ⇑F+

pcX is the poset of upper sets of nonempty finite elements ofPpcX, ordered by reverse inclusion. We have monads ⇓Ppc and ⇑F+

pc on Poset.Using the distributive law λX : ⇑F+

pc⇓PpcX → ⇓Ppc⇑F+pcX, we obtain a composite monad

⇓Ppc⇑F+pc on Poset.

The functor ⇓Ppc : Poset → Poset assigns to a poset X, the poset of lower sets of PpcX,ordered by inclusion. The functor ⇑F+

pc : Poset → Poset assigns the poset of upper sets offinite sets in PpcX, ordered by reverse . . .

23

TS-algebras and morphisms form a category CTS . There are evident forgetful functors fromCTS to CT and CS . Thus, we have the following commutative square of forgetful functors:

CTS - CT

CS?

GS- C

GT

?

The functors leading to C have left adjoints FS and F T . We may ask if the functors going outof CTS have left adjoints too. The results of Beck [Bec69] show that the functor CTS → CS

always has a left adjoint while the functor CTS → CT may not always have one, but if it doesit will be a certain coequalizer. We examine these functors below:

1. Note that an S-algebra is a map σ : SX → X and such algebras form a category CS . Weobtain a monad T on CS by first defining a functor T : CS → CS :

〈X, σ : SX → X〉 7→ 〈TX, λX ;Tσ : STX → TSX → TX〉f : 〈X,σ〉 → 〈Y, ψ〉 7→ Tf : 〈TX, λX ;Tσ〉 → 〈TY, λY ;Tψ〉

One verifies that Tf is a morphism of S-algebras. Likewise, the natural transformationsηT

X : X → TX and µTX : TTX → TX are also morphisms of S-algebras. Thus we obtain

monad T , which is called the lifted monad of T on CS .

Now, a T -algebra in CS is a map τ : T 〈X,σ〉 → 〈X,σ〉 which must be a morphism ofS-algebras, i.e.,

STXSτ

- SX

TX

λX ;Tσ? τ

- X

σ?

If α : TSX → X is a TS-algebra, then by taking σ = αS and τ = αT , the above squareis nothing but (7). Thus, every TS-algebra on C can be viewed as a T -algebra on CS

and we have an embeddingCTS Φ- (CS)eT

It turns out that this is in fact an isomorphism. Thus, the adjunction F T a GT : (CS)eT →CS applies to CTS → CS (upto isomorphism).

2. Coequalizer . . .

Example 26 Consider the monads list,Z〈−〉 : Set → Set whose algebras are monoids andabelian groups respectively. With the distributive law λX : listZ〈X〉 → Z〈listX〉

lambdaX : ΠiΣjkijxj 7→ Σj(Πikij)xj

we obtain the composite monad Z〈list−〉. The algebras of this monad are rings. Evidently,rings are abelian groups in the category of monoids.

Example 27 Consider the monads P1,P+ : Set → Set whose algebras are pointed sets andaffine complete semilattices (structures with nonempty sups) respectively. We can define adistributive law λX : P+P1X → P1P+X by:

{∅} 7→ ∅a 6= {∅} 7→ {{x : {x} ∈ a }}

24

Thus we obtain a composite monad P1P+ which is isomorphic to the powerset monad. Theisomorphism σX : P1P+X → PX is given by

∅ 7→ ∅{a} 7→ a

Thus, one can view complete semilattices as pointed affine complete semilattices.There is also a distributive law in the reverse direction κX : P1P+X → P+P1X given by

∅ 7→ {∅}{a} 7→ { {x} : x ∈ a }

25

References

[Bec69] J. Beck. Distributive laws. In B. Eckman, editor, Seminar on Triples and CategoricalHomology Theory, volume 80 of Lect. Notes Math., pages 119–140. Springer-Verlag,1969.

[Hub61] P. Huber. Homotopy theory in general categories. Math. Ann., 144:361–385, 1961.

[Mes83] J. Meseguer. Order completion monads. Algebra Universalis, 16:63–82, 1983.

[Mog91] E. Moggi. Notions of computations and monads. Inf. Comput., 93:55–92, 1991.

[Wad92] P. Wadler. The essence of functional programming. In ACM Symp. on Princ. ofProgram. Lang., pages 1–14, 1992.

26