- I'm having some trouble enmeshing my haskell intuition for monads with the rigor, so this
- A category is said to be monadi is an expository note to bridge the gap.
§ What is a monad
- A monad is an endofunctor
T: C -> Cequipped with two natural transformations: - (1)
return/eta: idC => T[yeeta, since we are yeeting into the monad. ] - (2)
join/mu: T^2 => T, such that two laws are obeyed:
- First law:
mu, Tcommutation:
T^3(x) --T(@mu@x)--> T^2@x| |mu@(T@x) mu@x| |v vT^2(x)---mu@x-----> T(x)- Second law:
mu, etacancellation:
(Tx) --eta@(T@x)--> T^2(x)|EQ || |T@(eta@x) mu@x| |v EQvT^2(x)---mu@x---> T(x)-
mu . eta T = mu . T eta = 1
§ Monad from adjunction
- Any adjunction between a Free functor
F: L -> Hand a forgetfUl/Underlying functorU: H -> LF |- Ugives a monad. The categories are namedL, Hforlo, highin terms of the amount of structure they have. We go from low structure to high structure by the free functor. - The monad on
Lis given byT := UF. - Recall that an adjunction gives us
pullback: (F l -> h) -> (l -> U h)andpushfwd: (l -> U h) -> (F l -> h). The first is termed pullback since it takes a function living in the high space and pulls it back to the low space. - This lets us start with
(F l -> F l), peel aFfrom the left viapullbackto create(l -> U (F l)). That is we havereturn: l -> T l. - In the other direction, we are able to start with
(U h -> U h), peel aUfrom the right viapushforwardto create(F U h -> h). This allows us to create the counit asT^2 l = F U F U l = F (U F) U l -> F U l = T l.
§ Algebra for a monad .
- Any monad, given by
(T: C -> C, return: 1C => T, join: T^2 => T)has a category ofT-algebras associated to it. - The objects of
T-algare morphismsf: Tc -> c. - The morphisms of
T-algbetweenf: Tc -> candg: Td -> dare commuting squares, determined by anarr: c -> d
Tc -T arr-> Td| |f g| |v vc -arr-> d- The notation for the category as makes some sense, since it consists of objects of the form
Tc -> cwhich matches somewhat with the function notation. We should have written but maybe that's too unweildy.
§ Factoring of forgetful functor of adjunction
- Any adjunction
(F: L -> H, U: H -> L)with associated monadTallows us to factorU: H -> Las:
H -Stx-> L^T -forget-> L- So we write elements of
Hin terms of syntax/"algebra overL". We then forget the algebra structure to keep only the low form. - The way to think about this is that any object in the image of
Uin fact has a (forgotten) algebra structure, which is why we can first go toL^Tand then forget the algebraic structure to go back toL. It might be that this transition fromHtoL^Tis very lossy. This means that the algebra is unable to encode what is happening inHvery well.
§ Monadic adjunction
- Let us consider an adjunction
(F: L -> H, U: H -> L)with monadT. FactorUviaL^Tas:
H -Stx-> L^T -forget-> L- The adjunction is said to be monadic if in the factoring of
UviaL^T, it happens thatH ~= L^T. That is,Stxis an equivalence betweenHandL^T. - The way to think about this is that any object in the image of
Uin fact has a (forgotten) algebra structure, and this algebra structure actually correctly represents everything that was happening inH. - Another way to say the adjunction
F: L -> H: Uis monadic is to say that is thatFis monadic overU. We imagine the higher categoryHand the free functorFlying overLandU. - Warning : This is a STRONGER condition than saying that
UFis a monad.UFis ALWAYS a monad for ANY adjunction. This says thatH ~= L^T, via the factoringH -Stx-> L^T -forget-> L. - We sometimes simply say that
Uis monadic , to imply that there exists anFsuch thatUFis an adjunction and thatU ~= L^T.
§ Category of models for an algebraic theory
- A functor is finitary if it preserves filtered colimits.
- In particular, a monad
T : L -> Lis finitary if it preserves filtered colimits in C. - If a right adjoint is finitary, then so is its monad because its left adjoint preserves all colimits. Thus, their composite preserves filtered colimits.
- A category
His a category of models for an algebraic theory if there is a finitary monadic functorU : H -> Set.
§ Limits and colimits in categories of algebras
- We say that
His monadic overLiff the adjunctionF: L -> H: Usuch that the monadT: L -> L := UFgives rise to an equivalence of categoriesH ~= L^T.
§ Riehl: Limits and colimits in categories of algebras
Here, we learn theorems about limits and colimits in L^T.
§ Lemma 5.6.1: If U is monadic over F, then U reflects isos
- That is, if for some
f: h -> h', ifUf: Uh -> Uh'is an iso, then so isf. - Since the adjunction
F |- Uis a monadic adjunction (Uis monadic overF), we know thatH ~= L^T, andUequals the forgetful functor(H = L^T) -> L. - Write the arrow
f: h -> h'as an arrow inL^Tvia the commuting square datum determined byg: h -> h':
Tl-Tg->Tl'| |a a'| |v vl--g-->l'- Since we assume that
U(Tg)is iso, this means thatgis iso. This means that there exists ag'which is the inverse ofg. But this means that the diagram below commutes:
Tl<-Tg'-Tl'| |a a'| |v vl<-g'--l'- For a proof, we see that
a' . Tg = g . a'. Composing byg'on left, giving:g' . a' . Tg = a'. Composing byTg'on the right, we get:g'. a' = a' . Tg'. That's the statement of the above square. - This means we have created an inverse
Tg', which reflectsg'intoL^T.
§ Corollary 5.6.2: Bijective continuous functions in CHaus are isos
- When we forget to
Set, we see that bijections are the isos. Thus, inCHaus(compact haussdorff spaces) which is monadic overSet, we have that the arrows that forget to become isos in set, ie, continuous bijections are also isos.
§ Corollary 5.6.4: Any bijective homomorphism arising from a monadic adjunction which forgets to Set will be iso
- Follow the exact same proof.
§ Thm 5.6.5.i A monadic functor U: H -> L creates any limits that L has.
- Since the equivalence
H ~= L^Tcreates all limits/colimits, it suffices to show the result forU^T: L^T -> L. - Consider a diagram
D: J -> C^Twith image spanned by(T(D[j]) -f[j]-> D[j]). - Consider the forgotten diagram
U^TD: J -> Cwith image spanned byD[j]. Create the limit coneP(for product, since product is limit) with morphismspi[j]: P -> D[j]. We know this limit exists since we assume thatLhas this limit thatU^Tneeds to create. - We can reinterpret the diagram
D: J -> C^Tas a natural transformation between two functorsTop, Bot: J -> C. These functors areTop(j) := T(D[j]),Bottom(j) := D[j]. - The the natural transformation is given by
eta: Top => Bottom, with defneta(j) := D[j]-f[j]-> D[j]wheref[j]is given by the image of(T(D[j]) -f[j]-> D[j]). - So we see that
eta: Top => Botcan also be written aseta: TD => DsinceTop ~= TDandBot ~= D. - Now consider the composition of natural transformations
Const(TL) =Tpi=> TD =gamma=> Dall inJ -> C. This gives us a cone with summitTL. - This cone with summit
TLfactors throughLvia the unique morphismlambda: TL -> L. We wish to show that(TL -lambda-> L)is aT-algebra, and is the limit ofD. - Diagram chase. Ugh.
§ Corollary 5.6.6: The inclusion of a reflective subcategory creates all limits
- The inclusion of a reflective subcategory is monadic.
- This lets us create all limits by the above proposition.
§ Corollary 5.6.7: Any category monadic over Set is complete
-
Sethas all limits. - The forgetful functor
U: H -> Lcreates all limits thatL=Sethas. - Thus
Hhas all limits, ie. is complete.
§ Corollary 5.6.9: Set is cocomplete
- The contravariant power set functor
P: Set^op -> Setis monadic. -
Sethas all limits, andPcreates all limits. - Thus all limits of
Set^opexist, ie, all colimits ofSetexist.
§ Category of models for alg. theory is complete
TODO
§ Category of algebras has coproducts
- We show how to construct the free product of monoids via haskell. The same principle generalizes for any algebraic theory:
import Control.Monad(join)-- |(a*|b*)* ~~simplify~~> (a|b)*eval :: Monoid a => Monoid b => [Either [a] [b]] -> [Either a b]eval = map (either (Left . mconcat) (Right . mconcat))-- | a*|b* -> (a|b)* with no simplificationtranspose :: Either [a] [b] -> [Either a b]transpose = either (map Left) (map Right)-- | (a*|b*)* -> (a|b)* with no simplificationflatten :: [Either [a] [b]] -> [Either a b]flatten = join . map transpose-- force: eval = flatten | via coequallizer§ If is finitary and is complete and cocomplete, then so is
- We have already seen that if is complete then so is
- We have also seen that contains coproducs
- So is we show that has coequalizers, then we get cocomplete, since any colimit can be expressed as coproduct-coequalizer.
- To show that all coequalizers exists is to show that there is an adjoint to the functor
const: [C^T] -> [J -> C^T]whereJ := [a -f,g-> b]is the diagram category for coequalizers. - Recall that the adjoint sends a diagram
[J -> C^T]to the nadir that is the coequalizer inC^T. - See that the constant functor trivially preserves limits.
- To show that it possesses an adjunction, we apply an adjoint functor theorem (fuck me). In particular, we apply the general adjoint functor theorem, so we must show that the solution set condition is satisfied.
- Recall that the solution set condition for requires that for each , the comma category admit weakly initial objects.
- Unwrapping that definition: For each , there is a solution set. Tht is, there exists a small set and a family of objects and a family of morphisms such that any morphism in can be factored via some as .
- To apply the theorem, we must produce a solution set for every object in
[J -> C^T], that is, for each parallel pair of morphisms . - We will produce a solution set with a single element by creating a fork such that any other fork factors through this fork (perhaps non uniquely!) So we create:
- If we know how to create coequalizers in , then this would be easy: we literally just create a coequalizer.
- Instead, we create some "approximation" of the coequalizer with .
- To start with, we define in of the pair ).
- If would be the coequalizer of then we are done. But this is unlikely, since a monad need not preserve coequalizers.
- Instead, we simply calculate the coequalizer of and call this .
- Repeat inductively to form a directed limit (colimit).
- Monad preserves filtered colimits, since in , the left adjoint preserves all colimits, and the right adjoint preserves colimits since it simply forgets the data in