Monads from Comonads Comonads from Monads

Total Page:16

File Type:pdf, Size:1020Kb

Monads from Comonads Comonads from Monads Monads from Comonads—Prologue WG 2.8 Marble Falls Monads from Comonads Comonads from Monads Ralf Hinze Computing Laboratory, University of Oxford Wolfson Building, Parks Road, Oxford, OX1 3QD, England [email protected] http://www.comlab.ox.ac.uk/ralf.hinze/ March 2011 University of Oxford—Ralf Hinze 1-39 Monads from Comonads—Some context WG 2.8 Marble Falls Buy one get one free! A common form of sales promotion (BOGOF). University of Oxford—Ralf Hinze 2-39 Monads from Comonads—Some context WG 2.8 Marble Falls 1 Monads Monads, a success story. University of Oxford—Ralf Hinze 3-39 Monads from Comonads—Some context WG 2.8 Marble Falls A ! M B University of Oxford—Ralf Hinze 4-39 Monads from Comonads—Some context WG 2.8 Marble Falls A monad consists of a functor M and natural transformations r : I ! M j : MM ! M The two operations have to go together: j · rM = id M j · Mr = id M j · Mj = j · j M MM Mj j MMM MM rM id M M j M j M g g r j MM M MM j University of Oxford—Ralf Hinze 5-39 Monads from Comonads—Some context WG 2.8 Marble Falls 1 Comonads Comonads, not exactly a success story. University of Oxford—Ralf Hinze 6-39 Monads from Comonads—Some context WG 2.8 Marble Falls N A ! B University of Oxford—Ralf Hinze 7-39 Monads from Comonads—Some context WG 2.8 Marble Falls A comonad consists of a functor N and natural transformations e : N ! I d : N ! NN The two operations have to go together: Ne · d = id N eN · d = id N Nd · d = dN · d d NN e N NN d N id N N d Nd d e g g N NN NNN NN dN University of Oxford—Ralf Hinze 8-39 Monads from Comonads—Some context WG 2.8 Marble Falls The simplest of all: the product comonad. N = − × X e = outl d = id M outr University of Oxford—Ralf Hinze 9-39 Monads from Comonads—Some context WG 2.8 Marble Falls Why has the product comonad not taken off? University of Oxford—Ralf Hinze 10-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls 2 Adjunctions • One of the most beautiful constructions in mathematics. • They allow us to transfer a problem to another domain. • They provide a framework for program transformations. University of Oxford—Ralf Hinze 11-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls Let C and D be categories. The functors L : C D and R : C ! D are adjoint, L a R, L ≺ C ? D R if and only if there is a bijection between the hom-sets C (L A; B) =∼ D(A; R B) that is natural both in A and B. The witness of the isomorphism is called the left adjunct. It allows us to trade L in the source for R in the target of an arrow. Its inverse is the right adjunct. University of Oxford—Ralf Hinze 12-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls Perhaps the best-known example of an adjunction is currying. − × X ≺ C ? C Λ : C (A × X ; B) =∼ C (A; B X ) (−)X The left adjunct Λ is also called curry and the right adjunct Λ◦ is also called uncurry. University of Oxford—Ralf Hinze 13-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls − × X ≺ C ? C Λ : C (A × X ; B) =∼ C (A; B X ) (−)X The images of the identity are function application and the return of the state monad. app = Λ◦ id : C (B X × X ; B) r = Λ id : C (A; (A × X )X ) University of Oxford—Ralf Hinze 14-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls The images of the identity are the counit and the unit of the adjunction. : LR ! I η : I ! RL An alternative definition of adjunctions builds solely on these units, which have to satisfy L · Lη = id L R · ηR = id R LRL RLR R η L R L η id id L L L R R R University of Oxford—Ralf Hinze 15-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls 2 Comonads and monads Every adjunction L a R induces a comonad and a monad. N = LR M = RL e = r = η d = LηR j = RL University of Oxford—Ralf Hinze 16-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls The curry adjunction induces the state monad. M A = (A × X )X r = Λ id j = Λ (app · app) The monad supports stateful computations, where the state X is threaded through a program. University of Oxford—Ralf Hinze 17-39 Monads from Comonads—Adjunctions WG 2.8 Marble Falls The curry adjunction induces the costate comonad. N A = AX × X e = app d = (Λ id) × X The context can be seen as a store AX together with a memory location X , a focus of interest. University of Oxford—Ralf Hinze 18-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls 3 Transforming natural transformations • Adjunctions provide a framework for program transformations. • All the operations we have encountered so far are natural transformations. • To deal effectively with those we develop a little theory of ‘natural transformation transformers’. University of Oxford—Ralf Hinze 19-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls 3 Post-composition Every adjunction L a R gives rise to an adjunction L− a R− between functor categories. L L− ≺ ≺ C ? D then C E ? DE R R− C E (LF; G) =∼ DE (F; RG) University of Oxford—Ralf Hinze 20-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls We write b−c for the lifted left adjunct and b−c◦ for its inverse. α : LF ! G β : F ! RG bαc : F ! RG bβc◦ : LF ! G The lifted adjuncts can be defined in terms of the units of the underlying adjunction: bαc = Rα · ηF bβc◦ = G · Lβ University of Oxford—Ralf Hinze 21-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls 3 Pre-composition Post-composition dualizes to pre-composition. Consequently, every adjunction L a R also induces an adjunction −R a −L. L −R ≺ ≺ C ? D then E D ? E C R −L E D (FR; G) =∼ E C (F; GL) University of Oxford—Ralf Hinze 22-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls We write d−e◦ for the lifted left adjunct and d−e for its inverse. β : FR ! G α : F ! GL dβe◦ : F ! GL dαe : FR ! G Again, the lifted adjuncts can be defined in terms of the units of the underlying adjunction: dβe◦ = βL · Fη dαe = G · αR An aide-mémoire: b−c turns an L in the source to an R in the target, while d−e turns an L in the target to an R in the source. University of Oxford—Ralf Hinze 23-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls 3 Transformation transformers If we combine b−c and d−e, we can send natural transformations of type LF ! GL to transformations of type FR ! RG. The order in which we apply the adjuncts does not matter. bdαec = dbαce dbβc◦e◦ = bdβe◦c◦ University of Oxford—Ralf Hinze 24-39 Monads from Comonads—Program transformations WG 2.8 Marble Falls If we assume that L and R are endofunctors, then we can nest b−c and d−e arbitrarily deep. α : Lm F ! GLn dbαcm en : Rn F ! GRm An aide-mémoire: the number of bs corresponds to the number of Ls in the source, and the number of ds corresponds to the number of Ls in the target. University of Oxford—Ralf Hinze 25-39 Monads from Comonads—Comonads from monads WG 2.8 Marble Falls 4 Monads from comonads • Assume that a left adjoint is at the same time a comonad. • Then its right adjoint is a monad! • Dually, the left adjoint of a monad is a comonad. University of Oxford—Ralf Hinze 26-39 Monads from Comonads—Comonads from monads WG 2.8 Marble Falls The ‘transformation transformers’ allow us to systematically turn the comonadic operations into monadic ones and vice versa. r = bec : I ! R e = brc◦ : L ! I j = bdddeec : RR ! R d = ddbj c◦e◦e◦ : L ! LL University of Oxford—Ralf Hinze 27-39 Monads from Comonads—Comonads from monads WG 2.8 Marble Falls The curry adjunction, provides an example, where the left adjoint L = − × X is also a comonad. e = outl d = id M outr Consequently, L’s right adjoint R = (−)X is a monad with operations r = boutlc = Λ outl j = bddid M outreec = Λ (app · (app M outr)) The resulting structure is known as the reader monad. University of Oxford—Ralf Hinze 28-39 Monads from Comonads—Comonads from monads WG 2.8 Marble Falls A × X ! B =∼ A ! B X University of Oxford—Ralf Hinze 29-39 Monads from Comonads—Comonads from monads WG 2.8 Marble Falls Every (co)monad comes equipped with additional operations. The product comonad might provide a getter and an update operation: get = outr : L ! ∆X update (f : X ! X ) = id × f : L ! L where ∆X is the constant functor. The transforms of get and update correspond to operations called ask and local in the Haskell monad transformer library. ask = boutrc = Λ outr : I ! R ∆X local (f : X ! X ) = bdid × f ec = Λ (app · (id × f )) : R ! R University of Oxford—Ralf Hinze 30-39 Monads from Comonads—Comonads from monads WG 2.8 Marble Falls 4 Proof We have to show that the comonadic laws imply the monadic laws and vice versa.
Recommended publications
  • Ambiguity and Incomplete Information in Categorical Models of Language
    Ambiguity and Incomplete Information in Categorical Models of Language Dan Marsden University of Oxford [email protected] We investigate notions of ambiguity and partial information in categorical distributional models of natural language. Probabilistic ambiguity has previously been studied in [27, 26, 16] using Selinger’s CPM construction. This construction works well for models built upon vector spaces, as has been shown in quantum computational applications. Unfortunately, it doesn’t seem to provide a satis- factory method for introducing mixing in other compact closed categories such as the category of sets and binary relations. We therefore lack a uniform strategy for extending a category to model imprecise linguistic information. In this work we adopt a different approach. We analyze different forms of ambiguous and in- complete information, both with and without quantitative probabilistic data. Each scheme then cor- responds to a suitable enrichment of the category in which we model language. We view different monads as encapsulating the informational behaviour of interest, by analogy with their use in mod- elling side effects in computation. Previous results of Jacobs then allow us to systematically construct suitable bases for enrichment. We show that we can freely enrich arbitrary dagger compact closed categories in order to capture all the phenomena of interest, whilst retaining the important dagger compact closed structure. This allows us to construct a model with real convex combination of binary relations that makes non-trivial use of the scalars. Finally we relate our various different enrichments, showing that finite subconvex algebra enrichment covers all the effects under consideration.
    [Show full text]
  • Lecture 10. Functors and Monads Functional Programming
    Lecture 10. Functors and monads Functional Programming [Faculty of Science Information and Computing Sciences] 0 Goals I Understand the concept of higher-kinded abstraction I Introduce two common patterns: functors and monads I Simplify code with monads Chapter 12 from Hutton’s book, except 12.2 [Faculty of Science Information and Computing Sciences] 1 Functors [Faculty of Science Information and Computing Sciences] 2 Map over lists map f xs applies f over all the elements of the list xs map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs > map (+1)[1,2,3] [2,3,4] > map even [1,2,3] [False,True,False] [Faculty of Science Information and Computing Sciences] 3 mapTree _ Leaf = Leaf mapTree f (Node l x r) = Node (mapTree f l) (f x) (mapTree f r) Map over binary trees Remember binary trees with data in the inner nodes: data Tree a = Leaf | Node (Tree a) a (Tree a) deriving Show They admit a similar map operation: mapTree :: (a -> b) -> Tree a -> Tree b [Faculty of Science Information and Computing Sciences] 4 Map over binary trees Remember binary trees with data in the inner nodes: data Tree a = Leaf | Node (Tree a) a (Tree a) deriving Show They admit a similar map operation: mapTree :: (a -> b) -> Tree a -> Tree b mapTree _ Leaf = Leaf mapTree f (Node l x r) = Node (mapTree f l) (f x) (mapTree f r) [Faculty of Science Information and Computing Sciences] 4 Map over binary trees mapTree also applies a function over all elements, but now contained in a binary tree > t = Node (Node Leaf 1 Leaf) 2 Leaf > mapTree (+1) t Node
    [Show full text]
  • 1. Language of Operads 2. Operads As Monads
    OPERADS, APPROXIMATION, AND RECOGNITION MAXIMILIEN PEROUX´ All missing details can be found in [May72]. 1. Language of operads Let S = (S; ⊗; I) be a (closed) symmetric monoidal category. Definition 1.1. An operad O in S is a collection of object fO(j)gj≥0 in S endowed with : • a right-action of the symmetric group Σj on O(j) for each j, such that O(0) = I; • a unit map I ! O(1) in S; • composition operations that are morphisms in S : γ : O(k) ⊗ O(j1) ⊗ · · · ⊗ O(jk) −! O(j1 + ··· + jk); defined for each k ≥ 0, j1; : : : ; jk ≥ 0, satisfying natural equivariance, unit and associativity relations. 0 0 A morphism of operads : O ! O is a sequence j : O(j) ! O (j) of Σj-equivariant morphisms in S compatible with the unit map and γ. Example 1.2. ⊗j Let X be an object in S. The endomorphism operad EndX is defined to be EndX (j) = HomS(X ;X), ⊗j with unit idX , and the Σj-right action is induced by permuting on X . Example 1.3. Define Assoc(j) = ` , the associative operad, where the maps γ are defined by equivariance. Let σ2Σj I Com(j) = I, the commutative operad, where γ are the canonical isomorphisms. Definition 1.4. Let O be an operad in S. An O-algebra (X; θ) in S is an object X together with a morphism of operads ⊗j θ : O ! EndX . Using adjoints, this is equivalent to a sequence of maps θj : O(j) ⊗ X ! X such that they are associative, unital and equivariant.
    [Show full text]
  • Categories of Coalgebras with Monadic Homomorphisms Wolfram Kahl
    Categories of Coalgebras with Monadic Homomorphisms Wolfram Kahl To cite this version: Wolfram Kahl. Categories of Coalgebras with Monadic Homomorphisms. 12th International Workshop on Coalgebraic Methods in Computer Science (CMCS), Apr 2014, Grenoble, France. pp.151-167, 10.1007/978-3-662-44124-4_9. hal-01408758 HAL Id: hal-01408758 https://hal.inria.fr/hal-01408758 Submitted on 5 Dec 2016 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Distributed under a Creative Commons Attribution| 4.0 International License Categories of Coalgebras with Monadic Homomorphisms Wolfram Kahl McMaster University, Hamilton, Ontario, Canada, [email protected] Abstract. Abstract graph transformation approaches traditionally con- sider graph structures as algebras over signatures where all function sym- bols are unary. Attributed graphs, with attributes taken from (term) algebras over ar- bitrary signatures do not fit directly into this kind of transformation ap- proach, since algebras containing function symbols taking two or more arguments do not allow component-wise construction of pushouts. We show how shifting from the algebraic view to a coalgebraic view of graph structures opens up additional flexibility, and enables treat- ing term algebras over arbitrary signatures in essentially the same way as unstructured label sets.
    [Show full text]
  • Algebraic Structures Lecture 18 Thursday, April 4, 2019 1 Type
    Harvard School of Engineering and Applied Sciences — CS 152: Programming Languages Algebraic structures Lecture 18 Thursday, April 4, 2019 In abstract algebra, algebraic structures are defined by a set of elements and operations on those ele- ments that satisfy certain laws. Some of these algebraic structures have interesting and useful computa- tional interpretations. In this lecture we will consider several algebraic structures (monoids, functors, and monads), and consider the computational patterns that these algebraic structures capture. We will look at Haskell, a functional programming language named after Haskell Curry, which provides support for defin- ing and using such algebraic structures. Indeed, monads are central to practical programming in Haskell. First, however, we consider type constructors, and see two new type constructors. 1 Type constructors A type constructor allows us to create new types from existing types. We have already seen several different type constructors, including product types, sum types, reference types, and parametric types. The product type constructor × takes existing types τ1 and τ2 and constructs the product type τ1 × τ2 from them. Similarly, the sum type constructor + takes existing types τ1 and τ2 and constructs the product type τ1 + τ2 from them. We will briefly introduce list types and option types as more examples of type constructors. 1.1 Lists A list type τ list is the type of lists with elements of type τ. We write [] for the empty list, and v1 :: v2 for the list that contains value v1 as the first element, and v2 is the rest of the list. We also provide a way to check whether a list is empty (isempty? e) and to get the head and the tail of a list (head e and tail e).
    [Show full text]
  • The Expectation Monad in Quantum Foundations
    The Expectation Monad in Quantum Foundations Bart Jacobs and Jorik Mandemaker Institute for Computing and Information Sciences (iCIS), Radboud University Nijmegen, The Netherlands. fB.Jacobs,[email protected] The expectation monad is introduced abstractly via two composable adjunctions, but concretely cap- tures measures. It turns out to sit in between known monads: on the one hand the distribution and ultrafilter monad, and on the other hand the continuation monad. This expectation monad is used in two probabilistic analogues of fundamental results of Manes and Gelfand for the ultrafilter monad: algebras of the expectation monad are convex compact Hausdorff spaces, and are dually equivalent to so-called Banach effect algebras. These structures capture states and effects in quantum foundations, and the duality between them. Moreover, the approach leads to a new re-formulation of Gleason’s theorem, expressing that effects on a Hilbert space are free effect modules on projections, obtained via tensoring with the unit interval. 1 Introduction Techniques that have been developed over the last decades for the semantics of programming languages and programming logics gain wider significance. In this way a new interdisciplinary area has emerged where researchers from mathematics, (theoretical) physics and (theoretical) computer science collabo- rate, notably on quantum computation and quantum foundations. The article [6] uses the phrase “Rosetta Stone” for the language and concepts of category theory that form an integral part of this common area. The present article is also part of this new field. It uses results from programming semantics, topology and (convex) analysis, category theory (esp. monads), logic and probability, and quantum foundations.
    [Show full text]
  • Beck's Theorem Characterizing Algebras
    BECK'S THEOREM CHARACTERIZING ALGEBRAS SOFI GJING JOVANOVSKA Abstract. In this paper, I will construct a proof of Beck's Theorem char- acterizing T -algebras. Suppose we have an adjoint pair of functors F and G between categories C and D. It determines a monad T on C. We can associate a T -algebra to the monad, and Beck's Theorem demonstrates when the catego- ry of T -algebras is equivalent to the category D. We will arrive at this result by rst de ning categories, and a few relevant concepts and theorems that will be useful for proving our result; these will include natural tranformations, adjoints, monads and more. Contents 1. Introduction 1 2. Categories 2 3. Adjoints 4 3.1. Isomorphisms and Natural Transformations 4 3.2. Adjoints 5 3.3. Triangle Identities 5 4. Monads and Algebras 7 4.1. Monads and Adjoints 7 4.2. Algebras for a monad 8 4.3. The Comparison with Algebras 9 4.4. Coequalizers 11 4.5. Beck's Threorem 12 Acknowledgments 15 References 15 1. Introduction Beck's Theorem characterizing algebras is one direction of Beck's Monadicity Theorem. Beck's Monadicity Theorem is most useful in studying adjoint pairs of functors. Adjunction is a type of relation between two functors that has some very important properties, such as preservation of limits or colimits, which, unfortunate- ly, we will not touch upon in this paper. However, we need to know that it is indeed a topic of interest, and therefore worth studying. Here, we state Beck's Monadicity Theorem.
    [Show full text]
  • Monads and Side Effects in Haskell
    Monads and Side Effects in Haskell Alan Davidson October 2, 2013 In this document, I will attempt to explain in simple terms what monads are, how they work, and how they are used to perform side effects in the Haskell programming language. I assume you already have some familiarity with Haskell syntax. I will start from relatively simple, familiar ideas, and work my way up to our actual goals. In particular, I will start by discussing functors, then applicative functors, then monads, and finally how to have side effects in Haskell. I will finish up by discussing the functor and monad laws, and resources to learn more details. 1 Functors A functor is basically a data structure that can be mapped over: class Functor f where fmap :: (a -> b) -> f a -> f b This is to say, fmap takes a function that takes an a and returns a b, and a data structure full of a’s, and it returns a data structure with the same format but with every piece of data replaced with the result of running it through that function. Example 1. Lists are functors. instance Functor [] where fmap _ [] = [] fmap f (x : xs) = (f x) : (fmap f xs) We could also have simply made fmap equal to map, but that would hide the implemen- tation, and this example is supposed to illustrate how it all works. Example 2. Binary trees are functors. data BinaryTree t = Empty | Node t (BinaryTree t) (BinaryTree t) instance Functor BinaryTree where fmap _ Empty = Empty fmap f (Node x left right) = Node (f x) (fmap f left) (fmap f right) 1 Note that these are not necessarily binary search trees; the elements in a tree returned from fmap are not guaranteed to be in sorted order (indeed, they’re not even guaranteed to hold sortable data).
    [Show full text]
  • 1 Category Theory
    {-# LANGUAGE RankNTypes #-} module AbstractNonsense where import Control.Monad 1 Category theory Definition 1. A category consists of • a collection of objects • and a collection of morphisms between those objects. We write f : A → B for the morphism f connecting the object A to B. • Morphisms are closed under composition, i.e. for morphisms f : A → B and g : B → C there exists the composed morphism h = f ◦ g : A → C1. Furthermore we require that • Composition is associative, i.e. f ◦ (g ◦ h) = (f ◦ g) ◦ h • and for each object A there exists an identity morphism idA such that for all morphisms f : A → B: f ◦ idB = idA ◦ f = f Many mathematical structures form catgeories and thus the theorems and con- structions of category theory apply to them. As an example consider the cate- gories • Set whose objects are sets and morphisms are functions between those sets. • Grp whose objects are groups and morphisms are group homomorphisms, i.e. structure preserving functions, between those groups. 1.1 Functors Category theory is mainly interested in relationships between different kinds of mathematical structures. Therefore the fundamental notion of a functor is introduced: 1The order of the composition is to be read from left to right in contrast to standard mathematical notation. 1 Definition 2. A functor F : C → D is a transformation between categories C and D. It is defined by its action on objects F (A) and morphisms F (f) and has to preserve the categorical structure, i.e. for any morphism f : A → B: F (f(A)) = F (f)(F (A)) which can also be stated graphically as the commutativity of the following dia- gram: F (f) F (A) F (B) f A B Alternatively we can state that functors preserve the categorical structure by the requirement to respect the composition of morphisms: F (idC) = idD F (f) ◦ F (g) = F (f ◦ g) 1.2 Natural transformations Taking the construction a step further we can ask for transformations between functors.
    [Show full text]
  • MONADS and ALGEBRAS I I
    \chap10" 2009/6/1 i i page 223 i i 10 MONADSANDALGEBRAS In the foregoing chapter, the adjoint functor theorem was seen to imply that the category of algebras for an equational theory T always has a \free T -algebra" functor, left adjoint to the forgetful functor into Sets. This adjunction describes the notion of a T -algebra in a way that is independent of the specific syntactic description given by the theory T , the operations and equations of which are rather like a particular presentation of that notion. In a certain sense that we are about to make precise, it turns out that every adjunction describes, in a \syntax invariant" way, a notion of an \algebra" for an abstract \equational theory." Toward this end, we begin with yet a third characterization of adjunctions. This one has the virtue of being entirely equational. 10.1 The triangle identities Suppose we are given an adjunction, - F : C D : U: with unit and counit, η : 1C ! UF : FU ! 1D: We can take any f : FC ! D to φ(f) = U(f) ◦ ηC : C ! UD; and for any g : C ! UD we have −1 φ (g) = D ◦ F (g): FC ! D: This we know gives the isomorphism ∼ HomD(F C; D) =φ HomC(C; UD): Now put 1UD : UD ! UD in place of g : C ! UD in the foregoing. We −1 know that φ (1UD) = D, and so 1UD = φ(D) = U(D) ◦ ηUD: i i i i \chap10" 2009/6/1 i i page 224 224 MONADS AND ALGEBRAS i i And similarly, φ(1FC ) = ηC , so −1 1FC = φ (ηC ) = FC ◦ F (ηC ): Thus we have shown that the two diagrams below commute.
    [Show full text]
  • On Coalgebras Over Algebras
    On coalgebras over algebras Adriana Balan1 Alexander Kurz2 1University Politehnica of Bucharest, Romania 2University of Leicester, UK 10th International Workshop on Coalgebraic Methods in Computer Science A. Balan (UPB), A. Kurz (UL) On coalgebras over algebras CMCS 2010 1 / 31 Outline 1 Motivation 2 The final coalgebra of a continuous functor 3 Final coalgebra and lifting 4 Commuting pair of endofunctors and their fixed points A. Balan (UPB), A. Kurz (UL) On coalgebras over algebras CMCS 2010 2 / 31 Category with no extra structure Set: final coalgebra L is completion of initial algebra I [Barr 1993] Deficit: if H0 = 0, important cases not covered (as A × (−)n, D, Pκ+) Locally finitely presentable categories: Hom(B; L) completion of Hom(B; I ) for all finitely presentable objects B [Adamek 2003] Motivation Starting data: category C, endofunctor H : C −! C Among fixed points: final coalgebra, initial algebra Categories enriched over complete metric spaces: unique fixed point [Adamek, Reiterman 1994] Categories enriched over cpo: final coalgebra L coincides with initial algebra I [Plotkin, Smyth 1983] A. Balan (UPB), A. Kurz (UL) On coalgebras over algebras CMCS 2010 3 / 31 Locally finitely presentable categories: Hom(B; L) completion of Hom(B; I ) for all finitely presentable objects B [Adamek 2003] Motivation Starting data: category C, endofunctor H : C −! C Among fixed points: final coalgebra, initial algebra Categories enriched over complete metric spaces: unique fixed point [Adamek, Reiterman 1994] Categories enriched over cpo: final coalgebra L coincides with initial algebra I [Plotkin, Smyth 1983] Category with no extra structure Set: final coalgebra L is completion of initial algebra I [Barr 1993] Deficit: if H0 = 0, important cases not covered (as A × (−)n, D, Pκ+) A.
    [Show full text]
  • An Introduction to Applicative Functors
    An Introduction to Applicative Functors Bocheng Zhou What Is an Applicative Functor? ● An Applicative functor is a Monoid in the category of endofunctors, what's the problem? ● WAT?! Functions in Haskell ● Functions in Haskell are first-order citizens ● Functions in Haskell are curried by default ○ f :: a -> b -> c is the curried form of g :: (a, b) -> c ○ f = curry g, g = uncurry f ● One type declaration, multiple interpretations ○ f :: a->b->c ○ f :: a->(b->c) ○ f :: (a->b)->c ○ Use parentheses when necessary: ■ >>= :: Monad m => m a -> (a -> m b) -> m b Functors ● A functor is a type of mapping between categories, which is applied in category theory. ● What the heck is category theory? Category Theory 101 ● A category is, in essence, a simple collection. It has three components: ○ A collection of objects ○ A collection of morphisms ○ A notion of composition of these morphisms ● Objects: X, Y, Z ● Morphisms: f :: X->Y, g :: Y->Z ● Composition: g . f :: X->Z Category Theory 101 ● Category laws: Functors Revisited ● Recall that a functor is a type of mapping between categories. ● Given categories C and D, a functor F :: C -> D ○ Maps any object A in C to F(A) in D ○ Maps morphisms f :: A -> B in C to F(f) :: F(A) -> F(B) in D Functors in Haskell class Functor f where fmap :: (a -> b) -> f a -> f b ● Recall that a functor maps morphisms f :: A -> B in C to F(f) :: F(A) -> F(B) in D ● morphisms ~ functions ● C ~ category of primitive data types like Integer, Char, etc.
    [Show full text]