<<

Monads and Algebras - An Introduction

Uday S. Reddy

April 27, 1995

1 1 Algebras of monads

Consider a simple form of algebra, say, a with a binary operation. Such an algebra is a pair hX, ∗ : X × X → Xi. 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 F : Set → Set (the FX = X ×X). In general, given an endofunctor F : C → C on a category C, we can speak of the “algebras” for F , which are pairs hX, α : FX → Xi of an object X of C and an arrow α : FX → X. preserve the respective operations, i.e.,

F f FX - FY

α β ? f ? X - Y Now, in algebra, it is commonplace to talk about “derived operators.” Such an operator is 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 derived operators are just compositions of the standard operators and identity arrows:

id X X- X id ×α α X × (X × X) X - 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 we can embed the domains of all the derived operators. In particular, we should have embeddings I →. 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 possible compositions of F ’s and identity . For example, for the simple algebra with a binary operation, TX is the set of all binary trees over X. We can then define the collection of all derived 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 abstract form of “terms” over X. The mapα ¯ is then viewed as a “valuation” map, which gives values to such terms in X. So far, we have just restated algebras of functors as algebras of “closed” functors. If all we can 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 algebras of functors, we have to add the axiom explicitly after the fact. On the other hand, when we use 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 set of 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 by a functor F . Algebras of the form hX, α¯ : TX → Xi will automatically satisfy the associativity law (2) because the domain ofα ¯ already incorporates associativity. Let us look more closely at the structure required of “closed” functors. We need two natural transformations η : I →. T and µ : TT →. T . These transformations need not be embeddings any more because we expect that our abstract terms will be obtained by identifying many concrete terms. The transformation ηX regards an element of X as an abstract term. Think of 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 the resulting term as thx := ui. When the “closed” functor is freely generated, as in (2), a variable term pxq will be just x, and a composite term thx := ui will be just t[u/x]. But, in the more general context, they can be different. Nevertheless, they must satisfy the usual laws of substitution: thx := pyqi = t[y/x] pxqhx := ti = t thx := uhy := vii = thx := uihy := vi It turns out that every term has exactly one “variable” (which could be of an appropriate product type to accommodate multiple indeterminates). So, we can dispense with variable names and use the notation p•q for a variable term, thui for a substitution term and t[u] for a term of terms. In this notation, the laws of substitution should read as:

thp•qi = t p•qhti = t thuhvii = thuihvi

These considerations lead to the definition of monads:

Definition 1 A on a category C is a triple T = hT, η, µi of an endofunctor and two natural transformations as follows: TT

?µ T 6η I This data must satisfy the following “unit laws” and the “associativity law”

T- η ηT T- µ T ======TI TT IT = T TTT TT µ µT µ ? ? µ ? T ======TT - T The natural transformations η and µ are called the unit and the multiplication of the monad respectively.

The algebras for a monad will be pairs hX, α : TX → Xi of objects X and arrows α. Regard TX as a set of abstract terms denoting derived operators, and α as a valuation map that 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 thx := ui and evaluate it at once. These two evaluations must be equal. T α TTX - TX

µX α ? α ? TX - X

A morphism of T -algebras is an arrow h : hX, αi → hY, βi such that T h TX - TY

α β ? h ? X - Y (Note that this is unchanged from algebras of functors.) It is common practice to denote an algebra by its structure map TX →α X, because X is implicit in its type. A morphism of algebras is denoted by the notation:  TX   TY    h    α  -  β   ?   ?  X Y The category of T -algebras and algbera morphisms is denoted CT and called the Eilenberg- Moore category of T . A for T is an algebra of the form hT X, µX : TTX → TXi. The laws of algebras

ηTX- µTX- TX======TTX TTTX TTX

µX T µX µx ? ? µ ? TX TTX X- TX trivially follow from the properties of the monad T . In a set-theoretic context, the elements of a free algebra are simply the abstract terms obtained from T . In presenting the category of free T -algebras, one uses a simplification. Note that any morphism h : hT X, µX i → hT Y, µY i 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 = T f; µY : TX → TTY → TY . Thus, in presenting the category of free algebras, we can dispense with the 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 hT X, µX i.

• Arrows f : X →K Y are the arrows f : X → TY of C, understood as standing for ∗ morphisms f = T f; µY : hT X, µX i → hT Y, µY i.

4 The identity arrows are ηX : X → TX and the composition of f : X → TY and g : Y → TZ ∗ T is f; g . The Kleisli category CT is equivalent to the full subcategory of free algebras in C . In general, it would appear that Kleisli categories are useful for modelling syntax, i.e., the surface form of semantic descriptions or programs, as evidenced by [Mog91, Wad92]. On the other hand, Eilenberg-Moore categories play a role in structuring semantics, in particular, the various 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 (or sequences) over X. The unit ηX maps an element x ∈ X to the singleton sequence hxi and the multiplication µX maps a sequence of sequences hs1, . . . , sni to their concatenation s1 ··· sn. Put another way, an abstract term for the list monad is a formal product of the form x1 ··· xn. A variable term is just a product of a single variable x. The substitution x1 ··· xnhx1 := s1, . . . , xn := sni is the concatenation s1 ··· sn. A list-algebra is a pair hX, Π: list X → Xi where Π is a valuation that assigns to each formal product x1 ··· xn a value in X. The laws of list-algebras are then Π(x) = x Π(x1 ··· xnhx1 := s1, . . . , xn := sni) = Π((Πs1) ··· (Πsn)) Writing e for Πhi and x · y for Πhx, yi, we obtain the following laws as a consequence of the corresponding properties for list concatenation: x · e = x = e · x x · (y · z) = (x · y) · z

Thus, list-algebras are precisely monoids hX, ·, ei and morphisms are monoid morphisms. The free list-algebras are free monoids, i.e., lists with concatenation as the binary operation. The Kleisli category maps are functions of the form X → list Y . One can similarly define a nonempty list monad list+ : Set → Set. The algebras of this monad are semigroups hX, ·i. There is a multiset monad Set → Set with singleton multisets as the unit and multiset union as the multiplication. The following notation is useful in this context. Recall that a multiset over X is a function φ : X → N that is “finitary” in the sense that φ(x) = 0 for all but finitely many x. The set of such finitary functions is called the “N-span” of X, denoted NhXi. It will be convenient to write functions φ as finite formal sums k1x1 + ··· + knxn where ki ∈ N and xi ∈ X. (The elements x not listed in the sum are understood to have coefficients 0.) In this notation, a singleton multiset is just x regarded as a formal sum and multiset union is: n X X X X k1( l1ixi) + ··· + kn( lnixi) 7→ ( kjlji)xi i i i j=1 where, on the right, the outer P is fomal and the inner P is on naturals. These notations can be used for all K-span monads where K has addition. The Z-span monad Zh−i : Set → Set has abelian groups as algebras.

Example 3 Let M = hM, ·, ei be a monoid. An action of M (on a set) is a pair hX, α : X × M → Xi such that α(x, e) = x α(x, ab) = α(α(x, a), b) A morphism of M-actions f : hX, αi → hY, βi 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 that specifies 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 × M sends ((x, a), b) to (x, ab). The unit laws and the associativity law of the monad follow from the 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 main difference is that monoid is a structure on sets while a monad is a structure on functors. If R is a , we can define a monad R ⊗ − : Ab → Ab with unit x 7→ 1 ⊗ x and multiplication 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 finite sets 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 term of F is a finite set {x1, . . . , xn}. A variable term is a singleton set and abstract substitution {x1, . . . , xn}hx1 := a1, . . . , xn := ani is the union a1 ∪ · · · ∪ an. If hX, α : FX → Xi 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 and has ⊥ is the unit. Thus, algebras of F are pointed hX, ∨X , ⊥X i. Defining x ≤ y ⇐⇒ x ∨ y = y, one verifies that ≤ is a partial order. The element ⊥ is the least 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 giving singletons and the multiplication giving unions. W W The algebras of this monad are of the form hX, X : PX → Xi where the operation assigns to every subset a ⊆ X, an element of W a ∈ X. Reasoning as above, we can define a partial order x ≤ y ⇐⇒ W{x, y} = y and notice that W is the supremum operation with respect to this order. Thus, the algebras of the powerset monad are complete semilattices. The morphisms are sup-preserving functions, also called additive functions. (Complete semilattices are also complete lattices, but their morphisms preserve only sups.) S The free algebras of the powerset monad are of the form hPX, i. They are complete lattices, but have additional structure: they are atomic and form boolean algebras. One calls them complete atomic boolean algebras (CABAs). However, the morphisms of P-algebras do not preserve this additional structure. The Kleisli maps f : X →K Y are functions f : X → PY . Any such function f is essentially a binary relation between X and Y . Thus, the Kleisli category SetP is isomorphic to Rel, the and relations.

1 Example 6 The subsingletons monad P : Set → Set assigns to a set X the set of subsets of 1 X containing at most one element. Thus, an element of P X is either ∅ or a singleton {x}. The unit is ηX (x) = {x} and the multiplication is µX (∅) = µX {∅} = ∅, µX {{x}} = {x}. All this 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 simply adds an additional element ⊥ = ∅ to a given set X.

6 The algebras for this monad are pairs hX, α : X⊥ → Xi. Given that α(x) must be x for all x ∈ X, all that is left to be specified is α(⊥). Thus, the algebras are pointed sets, i.e., sets X with 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 the Eilenberg-Moore category. The Kleisli maps f : X →K Y are functions f : X → Y⊥ which are essentially partial functions f : X → Y . Thus, the Kleisli category is equivalent to Pfn, the category of sets and partial 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 monad by associating the unit η : x 7→ ↓{x} (where ↓a = { z ∈ X : ∃x ∈ a. z ≤ x }) and the multiplication µ : a 7→ S a. This is called the downsets monad on Poset. W ˆ The algebras of this monad are of the form hX, X : PX → Xi which are again complete W W semilattices. To see that X is a supremum operation, consider X a. If x ∈ a then ↓{x} ⊆ ↓a W W 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. S The free algebras are of the form hPˆX, i. These are complete lattices, but have additional structure. They are prime-algebraic with complete primes of the form ↓{x} for x ∈ X. (Note S that, for every a ∈ PˆX, a = { ↓{x} : x ∈ a }.) The Kleisli maps X → PˆY can be characterized as relations F ⊆ X × Y satisfying:

0 0 0 0 x ≥X x ∧ x F 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

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

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

At this point, it is useful to relate various notions of “algebraicity” for complete semilattices or, 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 ≤ W 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 ≤ W 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 is the 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 that covers ⊥X , i.e., k 6= ⊥X and x ≤ k =⇒ x = ⊥X ∨ x = k. X is said to be atomic if every element is the lub of atoms below it.

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

Example 8 Consider the functor Dˆ : Poset → Poset that assigns to a partial order X the poset of all directed downsets (also called ideals) over X, ordered by inclusion. The unit ηX sends x to the principal ↓{x} = { y : y ≤ x } and the multiplication µX sends a directed down-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 necessarily W↑ pointed). They are posets X with an operation : DˆX → X for lubs of directed downsets. The morphisms preserve directed sups (called Scott-continuous functions). S↑ The free algebras for the directed sets monad are of the form hDˆ(X), i. They are ideal completions of posets or, equivalently, algebraic cpo’s. (“Domains” are algebraic cpo’s with a countable .) ˆ The Kleisli maps X →K Y are monotone functions X → DY for posets X and Y . Such maps are called approximable maps and characterized as relations F ⊆ X × Y satisfying the following conditions:

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

2. If x0 ≥ x, x F y and y ≥ y0 then x0 F y0.

3. If x F y1 and x F y2, there exists y ≥ y1, y2 such that x F 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 ω-cpos bounded sets a has an upper bound bounded complete cpos consistent sets every finite a0 ⊆ a has an upper bound consistently complete cpos pairwise 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 merely Scott-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 coherent subsets 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. Scoh The free algebras of Pcoh are easy to recognize. They are of the form hPcohA, i and are called coherent spaces. They are partially ordered by inclusion and form coherent cpos. In addition, they have the property of being atomic. A morphism of coherent spaces is determined by 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 h|A|, ≤Ai. This is subject to the axiom: 0 0 0 0 x ≤ x ^_ y ≥ y =⇒ x ^_ y

8 In particular, note that x ≤ y implies x ^_ y. Such ordered webs are also called prime event structures. The morphisms of powebs are monotone coherence-preserving functions. This gives a category Poweb. ˆ The coherent downsets monad Pcoh : Poweb → Poweb assigns to a poweb A the set of ˆ coherent downsets of A, ordered by inclusion. The coherence relation for PcohA is as for webs above. ˆ _ W ˆ 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 W 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 are coherent cpos, i.e., posets where all pairwise consistent sets have lubs. ˆ ˆ Scoh The free algebras of Pcoh are of the form hPcohA, i. 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. x0 ≥ x, x F y and y ≥ y0 implies x0 F y0.

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

0 0 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 by defining Γ to be set of finite sets {a1, . . . , an} such that a1 ∪ · · · ∪ an is a consistent set. We have a functor Pcon : Con → Con which extends to a monad. ˆ Scon The free algebras of this monad, of the form hPconA, i, 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

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

Such structures are also called prime information systems. The morphisms are monotone consistency-preserving functions. This gives a category Pocon. ˆ There is a consistent downsets monad Pcon : Pocon → Pocon. Its algebras are partially Wcon ˆ ordered consistency structures (|A|, ΓA) equipped with an operation : PconA → A. As for coherent 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 = hX, ∼X i 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 the ∼ equivalence 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 is defined by duality. If C a category, a comonad on C is a triple L = hL, , δi) of an endofunctor and two natural transformations as follows: LL 6δ L

? I This data is subject to the axioms:

L L- Lδ L ======LI LL IL = L LLL LL 6 6 6 δ δL δ δ L ======LL  L The natural transformations  and δ are called the counit and comultiplication respectively. A for L is a pair hX, α : X → LXi such that

X Lα X======LX LLX LX 6 6 6 α δX α α X LX  X Morphisms of coalgebras are defined in the expected fashion: Lh LX - LY 6 6 α β h X - Y 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 complete semilattice PX of all subsets of X, ordered by inlcusion. The counit X : PX → X sends a W subet 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 hX α : X → PXi of a complete semilattice X and an additive W function α. The counit law for coalgebras means that X α(x) = x. So, α(x) is a set of approximations 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 ∈ X W to 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 : hX, αi → hY, βi 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 completely determined by its action on the atoms. Since complete atomic lattices are isomorphic to powersets PX with atoms X, and the morphisms 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 . We examine this connection. An adjunction is a pair of functors between two categories

F- C  A G together with a natural isomorphism:

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

(We are lower case letters for objects: x, y, z for the objects of C and a, b, c for the objects of A.) In this situation, one writes F a G : A → C and calls F the left adjoint of F and G the right adjoint of F . Each functor in the adjunction determines the other uniquely up to isomorphism. 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:

F- Set  Mon G where F is the functor X 7→ hlist X, ·, i and G is the underlying set functor hA, ·A, eAi 7→ A. We have a natural isomorphism:

∼ −1 φX,A : Mon(FX,A) = Set(X, GA): φX,A which means that the set of monoid morphisms FX → A is (naturally) one-to-one with the set of functions X → GA. Let us see the details. Given a function f : X → A, there exists a −1 unique monoid morphism h = φX,A(f): hlist X, ·, i → hA, ·A, eAi such that the restriction of h to X is f. It is given by hhx1, . . . , xni = f(x1) ·A ····A f(xn) Note that the composite GF : Set → Set assigns to a set X the set of lists over X (the underlying set of the free monoid). We know that this functor extends to a monad. This happens in general. Whenever F a G : C → A is an adjunction, the composite functor T = GF : C → C gives a monad on C. Dually, the composite functor L = FG : A → A gives a comonad on A. This situation may be pictured as follows:

F - C  A 6 G 6 T = GF L = FG (monad) (comonad)

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

ηx = φx,a(idF x): 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):

−1 εa = φx,a(idGa): F Ga →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 : GF GF →. GF δ = F ηG : F GF G →. 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 monads were associated with adjunctions. Indeed, it simplifies our work considerably to look for an adjunction that induces a monad to obtain the relevant data of the monad. The following example would be quite tricky to do without the use of adjunctions.

Example 13 A meet-semilattice is a pair hA, ∧Ai where ∧A is a meet operation (associative, commutative and idempotent binary operation). The morprisms preserve meets. This gives a category MSLat. We claim that there is an adjunction between posets and meet-semilattices F- Poset  MSLat. This means there is a natural isomorphism: G ∼ φX,A : MSLat(FX, hA, ∧Ai) = Poset(X,GhA, ∧Ai)

Take G to be the that maps hA, ∧Ai to the underlying poset hA, ≤Ai. The partial order of A is defined by x ≤A y ⇐⇒ x ∧A y = x. For the free functor F , define the upper set of a ⊆ X by ↑X a = { z ∈ X : ∃x ∈ a. z ≥X x }. Then, we can take FX to be the + S + meet-semilattice hFˇ X, i 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 is reverse inclusion, ⊇. + S The natural isomorphism φ maps a meet-semilattice homomorphism h : hFˇ X, i → (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 a homomorphism h(↑a) = V{ f(x): x ∈ a }. + The adjunction induces a monad on Poset, the nonempty finite upper set monad Fˇ : ˇ+ hX, ≤X i 7→ hF X, ⊇i. 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}

ˇ+ −1 The counit of the adjunction εA : hF GA, ∪i → A is φ (idGA). It is given by ^ ^ εA(↑a) = { idGA(x): x ∈ a } = a A A

ˇ+ ˇ+ ˇ+ So, the multiplication of the monad µX : F F X → X is GεFX . Since F X is ordered by reverse inclusion, an upper set of a finite set s is as actually downset. Denote it by ⇓s = { a : 0 S ˇ+ ∃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 1 • the subsingleton upper set monad Fˇ whose algebras are “topped” posets (posets with top 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 may also 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 = hA, ·A, eAi atomic if there is a 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 monoids h : hA, Ki → hB,Li is a morphism of monoids such that, whenever x = k1 ··· kn is an atomic factorization in A, h(x) = h(k1) ··· h(kn) is an atomic factorization in B. It is clear that atomic monoids hA, Ki are essentially free monoids generated by K and that atomic monoid morphisms are essentially functions between the sets of atoms. The category of atomic monoids is 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 the monoid list A. The counit A : list A → A is just multiplication hx1, . . . , xni 7→ x1 ··· xn. The comultiplication δA : list A → list list A maps a list hx1, . . . , xni to the list of singletons hhx1i,..., hxnii. Coalgebras of this comonad are pairs hA, α : A → list Ai of monoids A and structure maps α. It may be verified that they are precisely atomic monoids with α mapping each element x ∈ A to the lists of its atomic factors. F- The situation we found here is rather special. We started with an adjunction Set  Mon G 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 to Mon. 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 equivalent to 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

F- Set  CSLat G is also bimonadic. The induced monad on Set is the powerset monad P (Example 5). The induced comonad on CSLat is the powerlattice comonad (Example 12). The algebras of the powerset monad are precisely complete semilattices, and the coalgebras of the powerlattice comonad 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 found throughout programming language theory. For example, the co-Kleisli category of the power- lattice comonad has objects complete lattices and morphisms additive functions of the form f : PA → B. Since additive functions preserve unions in PA, f is uniquely determined by its 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 with all functions as arrows. The following example gives several applications of this feature in semantics.

Example 14 There is an adjunction

F- Cpo  Cpo⊥ G between the category of cpo’s and continuous functions and that of pointed cpo’s and strict W↑ continuous functions. (A pointed cpo is a cpo with a least element ⊥.) If X = hX, X i 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 hX⊥, ⊥i obtained by lifting. To each continuous function f : X → Y it assigns the evident strict extension f⊥ : hX⊥, ⊥i → hY⊥, ⊥i. The functor G gives the underlying cpo of a pointed cpo. The monad induced by the adjunction is lifting (−)⊥ : Cpo → Cpo⊥ with unit and multiplication given by . . . Evidently, the algebras of the monad are precisely pointed cpo’s with strict continuous functions as morphisms. The comonad induced by the adjunction is also lifting (−)⊥ : Cpo⊥ → Cpo⊥ which sends a pointed cpo hA, ⊥Ai to hA⊥, ⊥i. The counit and the comultiplication are given by . . . A coalgebra of this comonad is a pointed cpo hA, ⊥Ai equipped with a structure map α : hA, ⊥Ai → hA⊥, ⊥i which just “picks out” the bottom element ⊥A. A morphism of coalgebras is preserves 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⊥ → B between pointed cpo’s. Since the least element of A⊥ is always mapped to ⊥B, this is determined by a continous function A → B. Thus, the co-Kleisli category has pointed cpo’s for objects but all continous functions for morphisms. We often use the symbol ! for such a comonad when the co-Kleisli category is cartesian closed (with inspiration from linear logic). Many other structures over Cpo have such ! comonads. The category of coherent cpos CohCpo 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 whose co-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 continuous functions 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 S →. T that commutes with the units and multiplications in the evident fashion: σσ SS - TT

µS µT ? σ ? S - T 6 6 ηS ηT

I = I 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 then maps 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 injects + + nonempty finite sets F X to finite sets FX. So, F is a submonad of F. There is a monad morphism list → F (in fact, an epimorphism) that maps lists listX to finite sets of their elements FX. So, F is a quotient monad of list. If σ : S → T is a morphism of monads, it induces a functor Cσ : CT → CS between the corresponding 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 morphism f : hX, αi → hY, βi 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 Sf SX - SY

σX σY ? T f ? TX - TY

α β ? f ? X - Y where the top square is an instance of naturality and the bottom square commutes because f is a morphism of T -algebras. At the level of categories, this situation is depicted by: Cσ CT - CS

GT GS ? ? C = C + σ + 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 → Clist is the inclusion of semilattices in Mon. More interestingly, functors of this form are all induced by monad morphisms. More precisely, if G : CT → CS is a functor such that G CT - CS

GT GS ? ? C = C

16 then G = Cσ for a monad morphism σ : S → T . To recover σ from G, consider the action of T T G on the free algebra µX : TTX → TX. The image of µX is an S-algebra structure on TX T (since G preserves the underlying objects). Denote it byµ ¯X : STX → TX. Since G also preserves the underlying arrows of morphisms, we have

 TTX   TTY   STX   STY  T f T f  T  -  T   T  -  T  G :  µX   µY  7→  µ¯X   µ¯Y   ?   ?   ?   ?  TX TY TX TY for all morphisms h. Now, for any arrow f : X → Y in C, T f : TX → TY is a morphism of T -algebras. So, by setting h = T f, we find the commutative square:

ST f STX - STY

T T µ¯X µ¯Y ? T f ? TX - 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 monad σ morphism. Now, C hX, αi = hX, σX ; αi....

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 where h : A → B is a morphism of monoids. Any such morphism induces a functor from B-actions to A-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 which just forgets the least elements of pointed semilattices. Similarly, F is a submonad of P, Dˆ is a submonad of Pˆ etc. The induced functors are forgetful. More interestingly, the list monad and the free abelian monad Zh−i are both submonads of the free ring monad. The induced functors forget part of the structure of a ring. σ The epimorphism σ : list → F in induces a functor Set : SLat• → Mon which regards a pointed semilattice as a monoid (there by ignoring the fact that ∨ is commutative and idempotent).

17 4 Distributive laws and composite monads

Suppose we are given two monads S, T : C → C. Does their composite TS : C → C form a 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 has the source TTSS which does not match the required TSTS. But, all is not lost. If we have a 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 ηT ST ηS µ ST = ISTI - TSTS - TS To get some intuition for this notion, treat S and T as assigning to a set X two collections of terms SX and TX. The set TSX then contains terms formed from T with subterms formed P from S. Regard T -terms as formal “summations” i xi and S-terms as formal “products” Q P Q 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 Y X X Y xij −→ xi f(i) (4) i∈I j∈J(i) f∈ΠJ i∈I 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 over addition. 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 terms are evaluated in the same way. To motivate these laws, we use the term notation of Section 1 and assume a distribution operator λ that converts an ST -term of the form s[t] to a TS-term of the form t0[s0]. We write this as λ : s[t] 7→ t0[s0]. (There does not seem to be a way to represent this operator implicitly in the syntax.) We need to specify what happens if s or t is a variable term or a substitution term:

λ : s[p•q] 7→ p•q[s] λ : p•q[t] 7→ t[p•q] 0 0 0 0 00 0 0 0 00 0 λ : s[t1] 7→ t1[s ] λ : s [t2] 7→ t2[s ] λ : s2[t] 7→ t [s2] λ : s1[t ] 7→ t [s1] 0 0 00 00 0 0 λ : s[t1ht2i] 7→ t1ht2i[s ] λ : s1hs2i[t] 7→ t [s1hs2i] The first two rules say that the action of λ on variable terms is null. The next two rules say that distribution commutes with substitution. The following is a categorical statement of these ideas: Definition 17 If S = hS, ηS, µSi and T = hT, ηT , µT i are monads on a category C, a distribu- tive law of S over T is a natural transformation λ : ST →. TS such that S T T η T T η S S T S Sη η - -  λ  λ ST - TS ST - TS λT T λ Sλ λS STT - TST - TTS SST - STS - TSS

SµT µT S µST T µS ? λ ? ? λ ? ST - TS ST - TS

18 Lemma 18 If S and T are monads on C with a distrbutive law λ : ST →. TS, then the functor TS : 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 equal composites: S - η T S η S - ηT ηS I - TS - η S T - T η T Likewise for µT µS. The natural transformations ηT S : S →. TS and T ηS : T →. TS above are monad morphisms. The relevant diagrams are:

ηT SηT S T ηST ηS SS - TSTS TT - TSTS

µS µ µT µ ? ηT S ? ? T ηS ? S - TS T - TS 6 6 6 6 ηS η ηT η

I = I I = I 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. ηT S : S → TS and T ηS : T → TS are monad morphisms, and

3. the “middle unitary law” S T T η η -S TS======TSTS ======µ ? TS holds, then the composite ηT ST ηS µ λ = ST - TSTS - TS is a distributive law.

1 + 1 Example 20 Consider the monads P , list : Set → Set. In this example, we write P X as 1 + X = {} + X. The composite functor P list : Set → Set is isomorphic to list : Set → Set

19 + 1 which extends to a monad. So, one would expect to find a distributive law λX : list P X → 1 + P list X. It is given by hi 7→ 

hx1, . . . , xni 7→ hxi1 , . . . , xik i where xi1 , . . . , xik is the sequence of non- elements of hx1, . . . , xni. Put another way, think of list+X as the infinite coproduct X + X2 + X3 + ··· . Then + 1 list (P X) is (1 + X) + (1 + X)2 + (1 + X)3 + ··· = 1 + X + 1 + X + X + X2 + 1 + X + X + X + X2 + X2 + X2 + X3 + ···

1 + 2 3 while P (list (X)) is 1 + X + X + X + ··· . The distrbutive law λX sends each summand of the source to the same summand in the target space. 1 + The induced monad morphisms P → list and list → list are evident monics. The corresponding functors Mon → Set⊥ and Mon → SGrp are forgetful.

1 + Example 21 Consider the monads F and F on Set, whose algebras are pointed sets and 1 + semilattices respectively. The functor composition F F : Set → Set is isomorphic to F : + 1 1 + Set → Set which extends to a monad. The distributive law λX : F F X → F F X is given by {∅} 7→ ∅ a 6= {∅} 7→ {{ x : {x} ∈ a }} 1 + The same arguments apply to the comosition P P : Set → Set which forms a monad isomorphic to the powerset monad P on Set.

20 Suppose α : TSX → X is a TS-algebra. Since we have monad morphisms S →. TS and T →. TS, X has both a T -algebra structure and an S-algebra structure (which we denote by αT and αS respectively): ηT T ηS SX SX- TSX  X TX

α α T (5) S - ? α X In other words, from the valuation map for TS-terms, we can extract a valuation map αS for S-terms and another αT for T -terms. One would expect that these two evaluation maps compose to give back the original map: TX S - α T T α - (6) α TSX - X 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 of S-subterms followed by the evaluation of the T -term. Moreover, αS is “λ-distributive” over αT : λ STX X - TSX

SαT T αS ? ? SX TX (7)

α S - T  α X For example, if λ is the distribution operator (4) of products over sums, this says that the inner- Q P P Q 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 that multiplication 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 S T is an algebra for a composite monad TS, then SX −→α X and TX −→α X defined by (5) are S T algebra structures on X that satisfy (6) and (7). Conversely, if SX −→α X and TX −→α X are algebra structures on X satisfying (7), then TSX −→α X defined by (6) is an algebra of the composite monad.

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

Example 23 Consider the monads Fˆ, Dˆ on Poset. The composition of the functors DˆFˆ : ˆ ˆ ∼ ˆ ˆ Poset → Poset is isomorphic to P : Poset → Poset. The isomorphism σX : PX → DFX is: 0 0 ↓a 7→ ⇓{ ↓a : a ⊆fin a }

21 with the inverse being directed union. This isomorphism corresponds to the fact a cpo is a 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-semilattices ˇ ˆ ˆ ˇ and (topped) meet-semilattices respectively. We have a distributive law λX : F FX → F FX given 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 is ordered by reverse inclusion. So, a lower set by this order is also closure under supersets. This ˆˇ ˆˇ gives 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ˆ FˇX → X is an algebra, the structure map can be decomposed into αF : FˆX → X and ˇ αF : FˇX → X, which correspond to finite joins and finite meets respectively (Examples 7 and ˆ ˇ 13). We can then recover α as αF ◦ FˆαF whose action may be written as V V W V V ⇑ {↑a1,..., ↑an} 7→ ↓ { a1,..., an} 7→ { a1,..., an}

The distributive law gives the identity: W W W ( 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 ∧ (Wa) = W{ 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:

0 ˆˇ . ˇˆ • By symmetry, there is a distributive law λX : FFX → FFX which gives a composite monad FˇFˆ. This monad is isomorphic to the above composite monad. The distrbutive laws λ and λ0 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 are complete lattices with an infinite distributive law:

z ∧ (Wa) = W{ z ∧ x : x ∈ a }

Such structures are referred to as frames or complete Heyting algebras. The frame morphisms preserve sups and binary meets. As we have already noted the monad ∼ + isomorphism Pˆ = DˆFˆ, the free frame monad is a composite of three monads DˆFˆFˇ .

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 → PconFcon X gives a composite ˆ ˇ + monad PconFcon . Its algebras are distributive consistently-complete cpo’s. They satisfy the infinite distributive law:

z ∧ (Wcona) = Wcon{ z ∧ x : x ∈ a } if {z} ∪ a is consistent

ˆ ˆ ˇ + This is again a composite of three monads DFconFcon . One can also use pairwise compatible sets in place of consistent sets above. Bounded sets can also be used, except that

Example 25 If X is a poset, let PpcX denote the poset of pairwise compatible subsets (finite subsets) of X, ordered by inclusion. We have the usual adaptions. ⇓PpcX is the poset of lower + sets of elements of PpcX. ⇑FpcX is the poset of upper sets of nonempty finite elements of + PpcX, ordered by reverse inclusion. We have monads ⇓Ppc and ⇑Fpc on Poset. + + Using the distributive law λX : ⇑Fpc⇓PpcX → ⇓Ppc⇑FpcX, we obtain a composite monad + ⇓Ppc⇑Fpc on Poset. The functor ⇓Ppc : Poset → Poset assigns to a poset X, the poset of lower sets of PpcX, + ordered by inclusion. The functor ⇑Fpc : Poset → Poset assigns the poset of upper sets of finite sets in PpcX, ordered by reverse . . .

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

CTS - CT

GT ? GS ? CS - C The functors leading to C have left adjoints F S and F T . We may ask if the functors going out of 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 does it 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. We obtain a monad Te on CS by first defining a functor Te : CS → CS:

hX, σ : SX → Xi 7→ hT X, λX ; T σ : STX → TSX → TXi f : hX, σi → hY, ψi 7→ T f : hT X, λX ; T σi → hT Y, λY ; T ψi

One verifies that T f is a morphism of S-algebras. Likewise, the natural transformations T T ηX : X → TX and µX : TTX → TX are also morphisms of S-algebras. Thus we obtain monad Te, which is called the lifted monad of T on CS. Now, a Te-algebra in CS is a map τ : TehX, σi → hX, σi which must be a morphism of S-algebras, i.e., Sτ STX - SX

λX ; T σ σ ? τ ? TX - X If α : TSX → X is a TS-algebra, then by taking σ = αS and τ = αT , the above square is nothing but (7). Thus, every TS-algebra on C can be viewed as a Te-algebra on CS and we have an embedding Φ CTS - (CS)Te

It turns out that this is in fact an isomorphism. Thus, the adjunction FfT a GfT :(CS)Te → CS applies to CTS → CS (upto isomorphism).

2. Coequalizer . . .

Example 26 Consider the monads list, Zh−i : Set → Set whose algebras are monoids and abelian groups respectively. With the distributive law λX : listZhXi → ZhlistXi

lambdaX :ΠiΣjkijxj 7→ Σj(Πikij)xj we obtain the composite monad Zhlist−i. The algebras of this monad are rings. Evidently, rings are abelian groups in the category of monoids.

1 + Example 27 Consider the monads P , P : Set → Set whose algebras are pointed sets and affine complete semilattices (structures with nonempty sups) respectively. We can define a + 1 1 + distributive law λX : P P X → P P X by:

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

24 1 + Thus we obtain a composite monad P P which is isomorphic to the powerset monad. The 1 + isomorphism σX : P P X → PX is given by

∅ 7→ ∅ {a} 7→ a

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

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

25 References

[Bec69] J. Beck. Distributive laws. In B. Eckman, editor, Seminar on Triples and Categorical Homology 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. of Program. Lang., pages 1–14, 1992.

26