Monads Need Not Be Endofunctors

Similar documents
MONADS NEED NOT BE ENDOFUNCTORS

Monads Need Not Be Endofunctors

Semantics for algebraic operations

Monads and More: Part 4

Algebraic model structures

Applications of 2-categorical algebra to the theory of operads. Mark Weber

Elements of Category Theory

Monads and More: Part 4

Higher Order Containers

Cellularity, composition, and morphisms of algebraic weak factorization systems

An introduction to Yoneda structures

MONADS ON DAGGER CATEGORIES

The algebraicity of the lambda-calculus

On a Categorical Framework for Coalgebraic Modal Logic

Simulations in Coalgebra

MONADS ON DAGGER CATEGORIES

1 The Hyland-Schalke functor G Rel. 2 Weakenings

Reconsidering MacLane. Peter M. Hines

PART I. Abstract algebraic categories

Towards a Formal Theory of Graded Monads

A categorical view of computational effects

Categories, functors, and profunctors are a free cocompletion

IndCoh Seminar: Ind-coherent sheaves I

Category Theory. Travis Dirle. December 12, 2017

FROM LAX MONAD EXTENSIONS TO TOPOLOGICAL THEORIES

The formal theory of adjunctions, monads, algebras, and descent

1 Cartesian bicategories

NOTES ON ADJUNCTIONS, MONADS AND LAWVERE THEORIES. 1. Adjunctions

PART II.2. THE!-PULLBACK AND BASE CHANGE

A categorical model for a quantum circuit description language

1 Categorical Background

LOCALIZATIONS, COLOCALIZATIONS AND NON ADDITIVE -OBJECTS

Pseudo-distributive laws

Freyd is Kleisli, for Arrows

THE CARTESIAN CLOSED BICATEGORY OF GENERALISED SPECIES OF STRUCTURES

Categories and Modules

MONADS WITH ARITIES AND THEIR ASSOCIATED THEORIES

Commutative ring objects in pro-categories and generalized Moore spectra

FAMILIAL 2-FUNCTORS AND PARAMETRIC RIGHT ADJOINTS

A 2-CATEGORIES COMPANION

Notions of Computation Determine Monads

LAX FORMAL THEORY OF MONADS, MONOIDAL APPROACH TO BICATEGORICAL STRUCTURES AND GENERALIZED OPERADS

Mathematical Synthesis of Equational Deduction Systems. Marcelo Fiore. Computer Laboratory University of Cambridge

INTRODUCTION TO PART V: CATEGORIES OF CORRESPONDENCES

Semantics and syntax of higher inductive types

REFLECTING RECOLLEMENTS

Locally cartesian closed categories

FROM LAX MONAD EXTENSIONS TO TOPOLOGICAL THEORIES MARIA MANUEL CLEMENTINO AND WALTER THOLEN. To Manuela, teacher and friend

Partially ordered monads and powerset Kleene algebras

arxiv: v1 [math.qa] 9 Feb 2009

Logic for Computational Effects: work in progress

Weak ω-groupoids in Type Theory

NOTES ON ATIYAH S TQFT S

Categorical techniques for NC geometry and gravity

Topos Theory. Lectures 21 and 22: Classifying toposes. Olivia Caramello. Topos Theory. Olivia Caramello. The notion of classifying topos

Extensions in the theory of lax algebras

CATEGORIES ENRICHED OVER A QUANTALOID: ISBELL ADJUNCTIONS AND KAN ADJUNCTIONS

arxiv: v1 [math.ct] 15 Aug 2014

arxiv: v1 [math.at] 9 Aug 2016

Theories With Duality DRAFT VERSION ONLY

arxiv: v1 [math.ct] 11 May 2018

EXTENSIONS IN THE THEORY OF LAX ALGEBRAS Dedicated to Walter Tholen on the occasion of his 60th birthday

A unifying model of variables and names

Limit Preservation from Naturality

Abstracting away from cell complexes

From parametric polymorphism to models of polymorphic FPC

The synthetic theory of -categories vs the synthetic theory of -categories

Ordered Topological Structures

Categorical coherence in the untyped setting. Peter M. Hines

About categorical semantics

THE HEART OF A COMBINATORIAL MODEL CATEGORY

Axiomatics for Data Refinement in Call by Value Programming Languages

Involutive Categories and Monoids, with a GNS-correspondence

LAX DISTRIBUTIVE LAWS FOR TOPOLOGY, II

MONOIDAL DERIVATORS MORITZ GROTH

DESCENT FOR MONADS PIETER HOFSTRA AND FEDERICO DE MARCHI

CATEGORIES ENRICHED OVER A QUANTALOID: ISBELL ADJUNCTIONS AND KAN ADJUNCTIONS

On the Construction of Free Algebras for Equational Systems

Injective objects and lax idempotent monads

A CARTAN-EILENBERG APPROACH TO HOMOTOPICAL ALGEBRA F. GUILLÉN, V. NAVARRO, P. PASCUAL, AND AGUSTÍ ROIG. Contents

Second-Order Equational Logic

A NOTE ON ENRICHED CATEGORIES

Pseudo-commutative monads and pseudo-closed 2-categories

The Grothendieck construction for model categories

Second-Order Equational Logic

A brief Introduction to Category Theory

CONTRAVARIANCE THROUGH ENRICHMENT

D-manifolds and derived differential geometry

sset(x, Y ) n = sset(x [n], Y ).

REFLECTING RECOLLEMENTS. A recollement of triangulated categories S, T, U is a diagram of triangulated

Formal power series rings, inverse limits, and I-adic completions of rings

Towards Mac Lane s Comparison Theorem for the (co)kleisli Construction in Coq

Analysis and Construction of Logical Systems: A Category-Theoretic Approach

arxiv:math/ v1 [math.at] 6 Oct 2004

Topological Groupoids and Exponentiability

Categories and functors

Towards a Flowchart Diagrammatic Language for Monad-based Semantics

Normalisation by evaluation

Duality, Residues, Fundamental class

Algebraic Geometry

Transcription:

Monads Need Not Be Endofunctors Thorsten Altenkirch, University of Nottingham James Chapman, Institute of Cybernetics, Tallinn Tarmo Uustalu, Institute of Cybernetics, Tallinn ScotCats, Edinburgh, 21 May 2010

Motivation Monads are the most successful pattern in functional programming and Type Theory. Useful for modelling effects (e.g. error, state, etc), but also other programming idioms (e.g. generalized syntactic structures). Monads, and constructions on monads (such as monad transformers) are key to reusable strutures. Frequently, we find structures that fail to be monads as if for the only reason that the underlying functor is not an endofunctor. E.g., untyped/typed lambda calculus syntax (over finite contexts), finite-dimensional vector spaces etc. Can/should one develop a theory of such structures?

Example: Vector spaces Let F be the skeletal category of finite sets ( F = N). J f F Set is the obvious embedding. Let (R, +, 0,, 1) be a semiring. We define Vec F Set Vec m = df J f m R η m J f m Vec m η m i = df λj. if i = j then 1 else 0 ( ) (J f m Vec n) (Vec m Vec n) A a = df λj. i m a i A i j Check that: k η X = k ηx = id Vec X (l k) = l k

Relative monads Given a category C and another category J with a functor J [J, C]. A relative monad is given by an object function T J C, for any object X J, a map η X C(J X, T X ) (unit), for any objects X, Y J and map k C(J X, T Y ), a map k C(T X, T Y ) (Kleisli extension) satisfying for any X, Y J, k C(J X, T Y ), k η X = k, for any X J, η X = id T X C(T X, T X ), for any X, Y, Z J, k C(J X, T Y ), l C(J Y, T Z), (l k) = l k C(T X, T Z). T is functorial with T f = (η J f ) ; η and ( ) are natural.

Relative monads (ctd) Clearly T = Vec with J = F and J = J f is an instance. Ordinary monads arise as as the special case where J = df C, J = df Id C. Any monad (T, η, ( ) ) on C restricts to a relative monad (T, η, ( ) ) on J defined by T X = df T (J X ), η X = df η J X, k = df k.

Example: Untyped lambda calculus syntax Define T as the initial algebra of F [F, Set] [F, Set] defined by F G X = df J X + (G X G X + G (1 + X )) (the terms of untyped lambda calculus). T is a relative monad, with η the inclusion of variables to terms and ( ) substitution.

Example: Typed lambda calculus syntax Let Ty be the set of types of typed lambda calculus (over some base types). Let F Ty be the category whose objects are pairs (Γ, ρ) where Γ F and ρ Γ Ty and maps from (Γ, ρ) to (Γ, ρ ) are maps f F(Γ, Γ ) such that ρ = ρ f (the contexts and context maps). Let J F Ty [Ty, Set] be the natural embedding. T (the terms) can be defined as an initial algebra of a suitable endofunctor on [F Ty, [Ty, Set]]. T is a relative monad.

Example: Indexed Functors Let U be the category of small sets. The functor J U [U, Cat] views a small set as a category. IF [U, Cat] defined by IF A = df [[J U A, U], U] gives rise to a relative monad. The definitions of η and ( ) correspond to the continuation monad (apart from the size issue). This showed up in our work on indexed containers (LICS 09), which also form a relative monad.

Relative adjunctions Given two categories C, D together with a third category J and a functor J J C. Given L [C, D], R [D, C]: L J R (L is a relative left adjoint to R), if C(J X, R Y ) D(L X, Y ) A relative adjunction gives rise to a relative monad T = R L. T D L R J J C J

Kleisli and Eilenberg-Moore constructions Given a relative monad we can define its initial (Kl(T )) and terminal (EM(T )) splitting as a relative adjunction. Kl(T ) = J and Kl(T )(X, Y ) = df C(J X, T Y ). Kleisli categories for the examples: Vector spaces Finite dimensional vector spaces λ calculus (untyped/typed) contexts and substitutions. Indexed Functors Functors between different slices. To define EM(T ) we define the notion of an EM-algebra without referring to µ. An EM-algebra is given by family of maps a X C(J X, A) C(T X, A) such that a ρ η = ρ and a(a ρ k) = a ρ k

Relative Monads as monoids? Can we have a monoid form of relative monads? Here is a calculation in the end-coend calculus: C(JX, TY ) C(TX, TY ) X,Y J = = Y J Y J C( X J C(JX, TY ) TX, TY ) C(Lan J T (TY ), TY ) = [J, C](LanJ T T, T ) Assume henceforth that Lan J [J, C] [C, C] exists.

[J, C] is lax monoidal We can define for any objects F, G [J, C], an object G J F [J, C] by G J F = df Lan J G F. We can also define for any object F [J, C], a map λ F [J, C](Lan J J F, F ), for any object F [J, C], a map ρ F [J, C](F, Lan J F J), for any objects F, G, H [J, C], a map α H,G,F [J, C](Lan J (Lan J H G) F, Lan J H Lan J G F ). ([J, C], J, J, λ, ρ, α) is a lax monoidal category, i.e., J is functorial, λ, ρ, α are natural (however not generally isomorphisms) and satisfy certain coherence conditions.

Relative monads = lax monoids Relative monads on J are the same as lax monoids in the lax monoidal structure on [J, C], i.e., triples (T, η, µ) with T [J, C], η [J, C](J, T ) and µ [J, C](T J T, T ) such that J J T λ T η JT T J T T µ T J T µ T T Jη T J J T ρ T J (T J T ) T Jµ T J T α (T J T ) J T µ µ JT T J T µ T

Assume further conditions on J... Assume that, in addition to the existence of Lan J, J further satisfies these conditions: J is fully faithful, i.e., for any X, Y J, there is an inverse to the canonical map J X,Y J(X, Y ) C(J X, J Y ) given by J X,Y f = df J f, J is dense, i.e., for any X, Y C, there is an inverse to the canonical map K X,Y C(X, Y ) [J op, Set](C(J, X ), C(J, Y )) given by K X,Y g f = df g f, For any F J C, X J, Y C, there is an inverse to the canonical map L F X,Y Lan J(C(J X, F )) Y C(J X, Lan J F Y ). The functors J F Set and J F Ty [Ty, Set] enjoy these properties.

[J, C] is monoidal, relative monads = monoids Then ρ, λ, α have inverses definable in terms of J 1, K 1, L 1. Hence [J, C] is (properly) monoidal. A relative monad T on J is a (proper) monoid in [J, C].

Relative monads extend to monads We also get that T extends to a monad on C (a monoid in the strict monoidal category ([C, C], Id, )). Define T = df Lan J T, η = df µ = df Id λ 1 Id Lan J J Lan J η Lan J T, Lan J T Lan J T α 1 T,T,Id Lan J (Lan J T T ) Lan J µ Lan J T (T, η, µ ) is a monad on C. E.g., untyped lambda calculus syntax extends to a monad on Set, typed lambda calculus syntax to a monad on [Ty, Set].

Relative monads extend to monads (ctd) Furthermore, the defining adjunction of Lan J, [C, C] J [J, C] Lan J lifts to an adjunction Mnd(C) ( ) ( ) RMnd(J)

Summary No conditions on J Monads restrict to relative monads Huber s theorem, Kleisli, E-M constructions Lan J exists [J, C] lax monoidal, relative monads = lax monoids Further conditions on J [J, C] monoidal, relative monads = monoids Relative monads extend to monads, coreflection

Arrows Given a category J, a (weak) arrow on J is given by an object function R J J Set, for any objects X, Y J, a function pure J(X, Y ) R(X, Y ), for any X, Y, Z J, a function ( ) R(Y, Z) R(X, Y ) R(X, Z) satisfying pure (g f ) = pure g pure f, r pure id = r, pure id r = r, t (s r) = (t s) r. R extends to a functor J op J Set (an endoprofunctor on J); pure and are natural.

Arrows = relative monads on Yoneda Assume J is small. Let C = df [J op, Set], J Y X = J(X, Y ) (the Yoneda embedding). Lan J exists, J is well-behaved. An arrow on J (a functor R J op J Set with structure) is the same as a relative monad on J (a functor T J [J op, Set] with structure). Cf. Jacobs et al. (2006): Arrows on J are the same as monoids in the monoidal structure on [J op J, Set] (the category of endoprofunctors on J).

Conclusions Relative monads are a natural generalization of monads. They are smoothly formulated in Manes s style, the monoid form needs left Kan extensions. A large part of monad theory carries over with minimal adjustments. There is a clear relationship to ordinary monads. They cover important examples for programming, in particular, examples with size issues. They also subsume arrows.