Linear usage of state

We investigate the phenomenon that"every monad is a linear state monad". We do this by studying a fully-complete state-passing translation from an impure call-by-value language to a new linear type theory: the enriched call-by-value calculus. The results are not specific to store, but can be applied to any computational effect expressible using algebraic operations, even to effects that are not usually thought of as stateful. There is a bijective correspondence between generic effects in the source language and state access operations in the enriched call-by-value calculus. From the perspective of categorical models, the enriched call-by-value calculus suggests a refinement of the traditional Kleisli models of effectful call-by-value languages. The new models can be understood as enriched adjunctions.

1. Introduction 1.1. Informal motivation. The state-passing translation transforms a stateful program into a pure function. As an illustration, consider the following ML program which uses a single fixed memory cell l : int ref.
-fun f x = let val y = !l in l := x ; y end ; val f = fn : int -> int The state-passing translation transforms that program into the following pure function which takes the state as an argument and returns the updated state as a result.
x Our contribution in this paper is foundational, but let us speculate briefly on possible applications. State plays an important role in many aspects of semantics, including operational semantics and Hoare logic. The type !A ⊗ S can be thought of as a type of configurations (program/state pairs) for a general abstract machine. This might pave the way for a general framework for operational semantics, building on the ideas of Plotkin and Power [35].
We also note that variations on linear-use state-passing style are already used to accommodate a broad class of effects within pure languages such as Clean [1] and Mercury [45].
We also consider sum types and unspecified base types. We adopt the call-by-value calling convention because it is most natural one for effectful programs. For simplicity we choose a fine-grain language in which the order of evaluation is totally explicit. The full syntax, equational theory and framework for denotational semantics is in Section 3. Sum types are treated in Section 6. The types of the target language are essentially the minimal fragment of the enriched effect calculus (EEC, [8,7]) that is needed for the linear-use state-passing translation. To enforce linear usage, EEC borrows some techniques and notation from linear logic (!, ⊗, and ) but in a careful way, enforced by the following grammar: The full syntax, equational theory and framework for denotational semantics is in Section 2.
In Section 4 we provide a linear-use state passing translation from the source language to the target language The translation on types takes a type τ of the source language to a value type τ S of the target language, by induction on the structure of types: R. E. MØGELBERG AND S. STATON Theorem 4.3 says that the linear-use state-passing translation is fully complete: it describes a bijective correspondence between programs in the source language of type τ and programs in the target language of type τ S . This means that contextual equivalence is preserved by linear-use state-passing translation.
Enriched category theory. The constructions involved in the target language have an elegant categorical formulation: they can be modelled in any enriched category with copowers. For this reason we call the target language the enriched call-by-value calculus.

Recall that in categorical semantics a type A is interpreted as an object [[A]] of a category, a context Γ is interpreted as an object [[Γ]] of a category, and a term-in-context Γ t : A is interpreted as a morphism [[t]] : [[Γ]] → [[A]
]. In the enriched call-by-value calculus, there are two classes of type: computation types and value types. A categorical analysis must thus involve two categories: a category V whose objects interpret value types, and a category C whose objects interpret computation types. The structure of the types dictates the structure that the categories V and C must have: • For the product types (1, ×), V must have finite products in the categorical sense.
• For the tensor type (!A ⊗ B), V must act on C. This means that there is a functor (− 1 · − 2 ) : V × C → C such that 1 · X ∼ = X and (A × B) · X ∼ = A · (B · X). • For the linear function type , the action (− 1 · − 2 ) must have a right adjoint in its first argument. The linear function type ensures that the space of morphisms X → Y forms an object of V. So C is enriched in V, and the action structure provides copowers. There are many examples of enriched models, including categories of algebras and Kleisli categories (understood as 'closed Freyd categories' [27]). Full details are in Section 2.
In Section 5 we explain that the connection with Kleisli categories gives us a categorical explanation of the linear-use state-passing translation. We use a semantic approach to prove the full completeness of the translation. We show that the traditional models of effectful call-by-value languages, using monads and Kleisli constructions, form a coreflective subcategory of the enriched models, and that the state-passing translation is the unit of the coreflection. We call this a linear-use state monad. In Section 3.2 we show that every monad arises as a linear-use state monad. In brief, the argument is as follows. The right notion of monad for programming languages is 'strong monad T on a category V with finite products and Kleisli exponentials'; for every such monad T , the Kleisli category C is V-enriched and has copowers and is thus a model of the enriched call-by-value language. The object 1 in C induces a linear-use state monad on V (1.1) which is isomorphic to the original monad T on V.
For the simplest case, consider the following monad on the category of sets for storing a single bit. If we let V = C = Set and let S = 2 (there are two states), then the linear-use state monad is the usual state monad T X = 2 → (X × 2).

LINEAR USAGE OF STATE 5
In general, the linear-use state monad (1.1) arises from an adjunction that is parameterized in S. Atkey [3] has investigated monads that arise from parameterized adjunctions: in fact Atkey's parameterized monads are essentially the same as our enriched models. We return to this in Section 9.
1.4. Algebraic theories and state access operations. In order to explain the general connection between effects and state, we turn to the analysis of effects begun by Plotkin and Power [38]. Categorically, a finitary monad on the category of sets is essentially the same thing as an algebraic theory. Plotkin and Power proposed to use this connection to investigate computational effects from the perspective of universal algebra.
The analysis of Plotkin and Power centres around the correspondence between algebraic operations and generic effects. More precisely, for a monad T the following data are equivalent: (1) An algebraic operation: roughly, a functorial assignment of an n-ary function X n → X to the carrier of each T -algebra T (X) → X; (2) A generic effect: a function 1 → T (n). For instance, consider the store monad for a single bit of memory (using the isomorphic presentation T = ((−) × 2 × (−) × 2)). Each T -algebra ξ : T (X) → X supports an algebraic operation ? X : X × X → X in a functorial way: let x ? X y = ξ(x, 0, y, 1). If we understand elements of T -algebras as computations, then x ? X y is the computation that reads the bit in memory and then branches to either x or y depending on what was read.
The corresponding generic effect deref : 1 → T (2) is given by deref() = (0, 0, 1, 1). It can be thought of as the command that reads the bit and returns the contents of memory.
We have already explained ( §1.3) that all monads can be understood as linear-use state monads, T = (S (!(−) ⊗ S)). The data for algebraic operations and generic effects can equivalently be given in terms of the following structure on the state object S: (3) A state access operation: a morphism S → !n ⊗ S in the computation category C. For instance, let V = C = Set and S = 2. This gives a state monad for a single bit of memory, isomorphic to ((−) × 2 × (−) × 2). The state access operation corresponding to reading the bit is simply the function read : 2 → 2 × 2 given by read(i) = (i, i), which reads the store and returns the result along with the store.
In Section 8 we provide more examples and investigate a general framework for algebraic presentations of theories of effects using algebraic operations, generic effects and state access operations.
1.5. The enriched effect calculus. The work presented here grew out of work on the enriched effect calculus by Egger, Møgelberg and Simpson (EEC, [7,8,9,10]). The enriched call-by-value calculus that we introduce in this paper is a fragment of EEC and our categorical semantics is based on their work. Every model of EEC contains a monad, and one of the observations of [9] (see also [7,Example 4.2]) was that this monad can always be represented as a linear state monad. A special case of the embedding theorem [8,Theorem 4] shows that given a strong monad T on a category V with finite products and Kleisli exponentials we can embed V in a model of EEC preserving the monad and all other structure. This gives the motto: every monad embeds in a linear state monad.
Since the enriched call-by-value calculus is a fragment of EEC (as opposed to full EEC), we allow ourselves a broader class of models. In contrast to the earlier work on EEC, we do not include products among the computation types, since they are not needed in the state-passing translation, and so in our models the category C does not need to have products. This allows us to build models from Kleisli categories, which typically do not have products, and this makes the relationship with monad models and closed Freyd categories much more straightforward. In particular, in our setting every monad is a linear state monad.
Nonetheless, in Section 10 we show that EEC is a conservative extension of the enriched call-by-value calculus. This shows that there is a fully-complete linear-use state translation into EEC. This result is further evidence that EEC is a promising calculus for reasoning about linear usage of effects. The related papers [9,10] show how the linear-use continuation passing translation arises from a natural dual model construction on models of EEC, and use this to prove a full completeness theorem similar to that proven here for the linear-use state-passing translation. In fact, from the point of view of EEC the two translations are surprisingly similar: the linear-use state-passing translation is essentially dual to the linear-use continuation-passing translation. This observation goes back to the work on EEC and indeed duality plays a key role in [9] (although the relationship with state wasn't made explicit there). We draw it out explicitly in Section 7.
Acknowledgements. We thank Alex Simpson for help and encouragement. Also thanks to Lars Birkedal, Jeff Egger, Masahito Hasegawa, Shin-ya Katsumata and Paul Levy for helpful discussions. Diagrams are typeset using the xymatrix package and Paul Taylor's diagrams package.

Enriched call-by-value: a calculus for enriched categories with copowers
The target language for the linear-use state translation is a new calculus called the enriched call-by-value calculus (ECBV), that we now introduce. As we will explain, it is an internal language for enriched categories with copowers.
The enriched call-by-value calculus is a fragment of the enriched effect calculus (EEC), which was introduced by Egger et al. [8,7] as a calculus for reasoning about linear usage in computational effects. The types of ECBV can be understood as a fragment of linear logic that is expressive enough to describe the linear state monad, S !(−) ⊗ S. We will not dwell on the connection with linear logic here.
2.1. Type theory and equational theory. The enriched call-by-value calculus has two collections of types: value types and computation types. We use α, β, . . . to range over a set of value type constants, and α, β, . . . to range over a disjoint set of computation type constants. We then use upright letters A, B, . . . to range over value types, and underlined letters A, B, . . . to range over computation types, which are specified by the grammar below: Note that the construction !A ⊗ B is indivisible: the strings !α and α ⊗ β are not well-formed types. The stratification of types means that one cannot chain function types: the string α (β γ) is not well-formed.
Readers familiar with Levy's Call-by-Push-Value [26] or EEC [8] should note that there are no type constructors F and U for shifting between value and computation types and that computation types are not included in the value types. The only way to shift between value types and computation types is by using tensor and function types. As we will see, this is the essence of the state-passing translation.
The enriched call-by-value calculus has two basic typing judgements, written In the both judgements, Γ is an assignment of value types to variables. In the first judgement, B is a value type, and in the second judgement, both A and B need to be computation types. The second judgement should be thought of as a judgement of linearity in the variable z : A. These judgements are defined inductively by the typing rules in Figure 1, which are a restriction of the rules of EEC [7] to this type structure. In the figure, ∆ is an assignment of a computation type to a single variable, as in (2.1). The ideas behind the term language for the function space A B and the tensor !A ⊗ B go back to the early work on linear lambda calculus. In particular, the introduction rule for !A ⊗ B uses pairing, and the elimination rule uses a pattern matching syntax.

2.2.
Enriched call-by-value models. The categorical notion of model for ECBV involves basic concepts from enriched category theory [21]. In summary, a model of the language comprises two categories, V and C, interpreting the value and computation types respectively; the function type A B provides an enrichment of C in V, and the universal property of the tensor type !A ⊗ B is the copower, sometimes called tensor.
We now make this precise. Let us recall some rudiments. Following [18,14], we begin with actions of categories. Let V be a category with finite products (by which we mean that it has a chosen terminal object and chosen binary products). Recall that an action of V on a category C is a functor · : V × C → C together with two natural isomorphisms, unit (1 · A) ∼ = A and associativity ((A × B) · C) ∼ = (A · (B · C)), that cohere with the isomorphisms arising from the product structure of V in the following sense: (We underline objects of C to distinguish them from objects of V.) An enrichment of a category C in V with copowers is determined by an action of V on C such that each functor (− · B) : V → C has a right adjoint, C(B, −) : C → V. Then A · B is called a copower, and C(B, C) is called enrichment. We write Hom C (B, C) for the usual hom-set of C to distinguish it from the enrichment.
Equality. (We elide α-equivalence, reflexivity, symmetry, transitivity and congruence laws.) This definition is made by induction on the structure of typing derivations, making use of the universal properties of the interpretations of the types. For illustration, we consider the following two rules: . u : C In dealing with the linear lambda abstraction rule, the induction principle gives us an interpretation in V, using the natural bijection that defines the relationship between the copower and the enrichment: Proposition 2.2. The interpretation of the enriched call-by-value calculus in an enriched model (V, C) is sound: Proof notes. This is proved by induction on the structure of the derivation of (≡). The following substitution lemma is helpful: If Γ | ∆ t : A and Γ | z : A u : B then u[t/z] is the following composite morphism in C: 2.3. Examples of enriched models. We now list some examples of enriched models (Definition 2.1).
(1) If V = Set then a V-enriched category is just a locally small category. The copower A · B is the A-fold iterated coproduct of B, if it exists. The following three examples are instances of this example. (2) Let V = Set and let C be the category of monoids and homomorphisms. The copower A · B, where A is a set and B is a monoid, can be described as a quotient of the free monoid on the product of sets, (A × |B|) * / ∼ . Here (A × |B|) * is the set of strings built of pairs in (A × |B|), which is a monoid under concatenation with the empty string as unit. The equivalence relation (∼) is generated by (a, b).(a, b ) ∼ (a, b.b ) and ∼ (a, ).
There is a similar description of the copower for any algebraic theory. (3) We can modify Example (2) to make C the category of free monoids and monoid homomorphisms. That is, the objects are monoids of the form B * . In this situation, the copower satisfies A · B * = (A × B) * . In this example C is the Kleisli category for the free monoid monad. We will revisit Kleisli categories in Section 3.2. (4) Let V = C = Set, with C considered with the ordinary enrichment. The copower A · B is the cartesian product of sets. This situation generalizes to the situation where V = C is an arbitrary cartesian closed category. (5) Let V be the category of ω-cpo's and continuous functions, and let C be the category of pointed ω-cpo's and strict functions. The enrichment C(A, B) is the cpo of strict functions under the pointwise order, and the copower A · B is the smash product A ⊥ ⊗ B. (6) In the next section we will investigate a model built from the syntax of the enriched call-by-value calculus.
2.4. The syntactic enriched model. The types and terms of the enriched call-by-value calculus form an enriched model which we call the syntactic enriched model. Let V be the category whose objects are value types and where a morphism A → B is a term in context x : A | − t : B modulo the equational theory ( Figure 1) and modulo renaming the free variable x. The identity morphism is the term x : A | − x : A, and composition of morphisms Since morphisms are actually equivalence classes, the well-definedness of substitution depends on the following substitution lemma The laws of associativity and identity for composition are immediate. For instance, associativity amounts to the following syntactic identity: The category V has products, given by the product types. The equations at product types are exactly what is needed to guarantee the universal properties.
Let C be the category whose objects are computation types and where a morphism A → B is a term in context − | z : A t : B modulo the equational theory and modulo renaming the free variable z. Identities and composition are defined in a similar way to V. The identity morphisms A → A are − | z : A z : A and composition is by substitution.
The action of V on C is given on objects by the tensor type: let Functoriality follows from the equational theory of ECBV. The unit and associativity isomorphisms are straightforward to define. For example, associativity ((A × B) · C ∼ = A · (B · C)) is given by exhibiting mutual inverses at all types: It follows from the equational theory of ECBV that these are isomorphisms and are natural and coherent. Finally, we discuss the enrichment of C in V. Given types A, B and C we describe a natural bijection 2.5. Universal property of the syntactic enriched model. The syntactic model described in Section 2.4 enjoys a universal property: it is an initial object in a category of enriched models with structure preserving functors as morphisms. Given any other enriched model, the unique morphism from the syntactic model is given by interpretation of syntax in the model. This semantic characterization of interpretation is standard in categorical semantics, and it is useful for deriving syntactic results from semantics, as we shall see in Section 5. However, we shall also see (Section 5.3) that we need to talk about morphisms of models preserving structure only up to isomorphism, and the syntactic model is not initial with respect to this collection of morphisms. Rather, interpretation defines a morphism which is unique only up to unique isomorphism. In order to formulate this kind of initiality, we need to be able to assess when two morphisms between enriched models are isomorphic. Thus the enriched models form a groupoid-enriched category, i.e., a 2-category in which each 2-cell is invertible. The idea of using groupoid-enriched categories of models has been around for a long time (e.g. [6, §8]) and has been used in previous work on the enriched effect calculus [8,9].
A precise definition of the 2-category of enriched models Enr can be found in Appendix A. Here we just state the initiality property of the syntactic model. First recall the following definition from 2-category theory (see e.g. [22, §6]). Definition 2.3. Let K be a 2-category. An object 0 of K is bi-initial if for any object A the hom-category K(0, A) is equivalent to the terminal category (i.e., the category with one object and one morphism).
An equivalent way of stating bi-initiality is to say that for any other object A there exists a 1-cell 0 → A which is unique up to unique 2-isomorphism.
The syntactic model of Section 2.4 is bi-initial in the category Enr, but in this paper we are much more interested in a category of enriched models (V, C) with a specified state object S in C (because of the relation to the state-passing translation), and so we formulate bi-initiality with respect to a category Ecbv of these. Like all other structure, 1-cells of Ecbv are only required to preserve the state objects up to isomorphism. (See Appendix A.2 for a full definition). We write (V ecbv , C ecbv , S) for the enriched model obtained as in Section 2.4 from the syntax of the enriched call-by-value calculus extended with a special computation type constant S.
The unique morphisms with domain (V ecbv , C ecbv , S) are given by interpretation of syntax into models.

Fine-grain call-by-value, a calculus for Kleisli models
The source language for our state-passing translation is a call-by-value language equipped with an equational theory to be thought of as generated by some operational semantics, as in [34]. We use a 'fine grain' call-by-value language, following Levy et al. [27,26]. We use α to range over type constants. The types are given by the grammar σ, τ : The function space is a call-by-value one, which takes a value and produces a computation. The fine-grain call-by-value calculus (FGCBV) has two typing judgements, one for values and one for producers. These are written Γ v V : σ and Γ p M : σ. The latter should be thought of as typing computations which produce values in the type judged but may also perform side-effects along the way. In both judgements the variables of the contexts are to be considered as placeholders for values. Typing rules along with equality rules are given in Figure 2.
The call-by-value language is called 'fine grain' because the order of evaluation is explicit. Notice that the string (f (x), g(y)) is not well-formed syntax: one must specify the order of evaluation, for instance, like this: Translations from a 'coarser grain', more natural programming language are given by Levy et al. ([27,§3] 3.1. Interpretation in Kleisli models. The most natural way to interpret fine-grain call-by-value is two have two categories V and C to interpret the judgements v and p , but to insist that the two categories have exactly the same objects, since in this language there is only one class of types.
Equality. (We elide α-equivalence, reflexivity, symmetry, transitivity and congruence laws.)  1) together with an identity-on-objects functor J : V → C that strictly preserves copowers, which means that J(A × B) = A · J(B) (naturally in A and B) and that the canonical isomorphisms induced by the product structure are the coherent unit and associativity isomorphisms of the copowers: We will sometimes say 'Kleisli model' for 'enriched Kleisli model'. We use the name 'Kleisli' because this definition captures the situation where C is the Kleisli category for a strong monad on V. The correspondence is explained in Section 3.2.
Kleisli models have earlier been called 'closed Freyd categories' by Levy et al. [27]. Their original definition of closed Freyd category is based on premonoidal categories; the relationship with actions of categories and Kleisli models is observed by Levy  and we use these to define a morphism in C that interprets (M to x. N ):

As another example [[return
). This defines a sound and complete notion of model for FGCBV.

3.2.
Relationship with monads. We now explain the connection between enriched Kleisli models and Kleisli categories for a monad. For more detail, see the paper by Levy et al. [27].
From the syntactic point of view, the fine-grain call-by-value language can be thought of as a variant of Moggi's λ C [31]: the type construction (1 (−)) is a monad. From the semantic point of view, recall that a λ C -model [31] is a category with finite products and a strong monad with Kleisli exponentials. We now explain these conditions. Let V be a category with finite products, and let (T, η, µ) be a monad on V. Let C be the Kleisli category for T : the objects of C are the objects of V and a morphism A strength for a monad T is usually expressed as a family of morphisms A × T (B) → T (A × B) that respect the structure of the monad. In fact, a monad is strong if and only if there is an action of V on C and the identity-on-objects functor J : V → C preserves it. The strength is needed to take a morphism f : The requirement of Kleisli exponentials is normally expressed as the requirement that for all A and B, the hom-functor Hom V ((−) × A, T B) : V op → Set is representable. To endow V with Kleisli exponentials is to give a right adjoint for the action, i.e. an enrichment of C in V.
Conversely, every enriched Kleisli model (V, C, J) induces a strong monad on V with Kleisli exponentials. The monad is defined using the closed structure: The Kleisli category for this monad is isomorphic to C. On the other hand, if we begin with a monad, build the Kleisli category and then take the monad C(1, A), we recover a monad that is isomorphic to the one that we started with. In this sense, enriched Kleisli models and λ C -models are equivalent. Note that they are not exactly the same, for although the hom-set Hom V (A, C(1, B)) is in bijection with Hom C (A, B), the sets are typically not identical.
3.3. The syntactic Kleisli model. The types and terms of the fine-grain call-by-value calculus form a syntactic model. We employ the same kinds of technique as for enriched call-by-value in Section 2.4.
• The objects of both V and C are the types of FGCBV. Figure 2) and modulo renaming the free variable x. Identities are variables and composition is by substitution.
Composition is not by substitution, since one cannot substitute a producer term for a variable. Rather, the composite of • The product structure in V is given by the product types, projections and pairing.
• The action of V on C is given on objects by the binary product types: let σ · τ def = σ × τ .

On morphisms, given
• The identity-on-objects functor J : V → C takes a morphism σ We write (V fgcbv , C fgcbv , J) for the syntactic Kleisli model.

3.4.
Universal property of the syntactic Kleisli model. Appendix A.3 defines the 2-category Kleisli of Kleisli models. As was the case for Ecbv, 1-cells are only required to preserve structure up to isomorphism.
The unique morphisms with domain (V fgcbv , C fgcbv , J) are given by interpretation of syntax into models.

The linear-use state-passing translation
This section defines the linear-use state-passing translation from the fine-grain call-by-value calculus to the enriched call-by-value calculus, and states the main syntactic results of this paper: fullness on types and full completeness. Together these assert that the linear-use state-passing translation is an equivalence of languages.
We now fix a computation type S of ECBV. For now, it can be an arbitrary computation type; later we will make it a distinguished basic type to achieve a full completeness result. We will describe a translation from FGCBV to ECBV. When S is thought of as a type of states, then this translation reads as a state-passing translation.
We translate FGCBV types σ to ECBV value types σ S : We extend this translation to type contexts, taking an FGCBV type context Γ to an ECBV type context Γ S . The translation on terms is syntax-directed. We pick a variable s, completely fresh. The translation takes an FGCBV value type judgement Γ v V : σ to an ECBV judgement Γ S | − V S : σ S , and an FGCBV producer judgement Γ p M : σ to an ECBV judgement The translation is defined as follows.
In the case for λ-abstraction, the z is chosen to be completely fresh.
The translation respects types. For instance The linear-use state-passing translation is sound: This result can be proved by induction on the structure of equality (≡) derivations, but it can also be derived semantically as we shall see in Section 5.4.

Full completeness.
We now state our main theorems: fullness on types and full completeness on terms. To state fullness on types we need to talk about isomorphism of types in ECBV. This can be defined in the usual way: for value types, an isomorphism A ∼ = B is given by two judgements, x : A | − t : B and y : A composing in both directions to identities. We note the following type isomorphisms, inherited from the enriched effect calculus [8, §3]: Theorem 4.2 (Fullness on types). Let A be a value type of ECBV formed using no other computation type constants than S. Then there exists an FGCBV type σ such that σ S ∼ = A.
Proof. By induction on the structure of types. The interesting case A B uses the fact that any computation type not using any α other than S is isomorphic to one of the form !C ⊗ S, which follows from the isomorphisms (4.1).
We now state our main syntactic result.
In Section 5.4 we sketch a semantic proof of Theorems 4.2 and 4.3.

A semantic proof of full completeness
In this section we present two constructions on models. The first ( §5.1) constructs a Kleisli model (Def which is easily seen to be functorial.
The right adjoint to The construction Kl described above extends to a 2-functor Kl : Ecbv → Kleisli from the 2-category of enriched models to the 2-category of Kleisli models. See Appendix C.2 for details.

5.2.
From Kleisli models to enriched models with state. Any Kleisli model is trivially an enriched model, so for the opposite construction we just need to pick a state object in a Kleisli model. We define St(V, C, J) def = (V, C, 1), where 1 is the terminal object of V considered as an object of C. This definition extends to a 2-functor St : Kleisli → Ecbv, as shown in Appendix C.
The motivation for this definition is that, as we now show, the 2-category Ecbv can be seen as a 2-category of enriched adjunctions, and the 2-functor St can be seen as an inclusion of Kleisli adjunctions into Ecbv.
Let (V, C) be an enriched model. By an enriched adjunction we mean an adjunction [20]).
Any choice of state object gives an enriched adjunction, since (− · S) is left adjoint to C(S, −) : C → V. The following proposition (first noted for EEC, [8, Proof of Thm. 4], [7]) shows that every enriched adjunction arises in this way: So enriched adjunctions correspond essentially bijectively to state objects. In particular the state object corresponding to a Kleisli model is 1. Monads induced by state objects can be described in ECBV as S !(−) ⊗ S. By the correspondence between Kleisli models and strong monads we arrive at the slogan: Every strong monad is a linear-use state monad. More directly, the slogan can be derived from the isomorphism Kl T (1, A × 1) ∼ = T (A), which holds for the Kleisli category Kl T of any strong monad T .
(Remark: if T is a strong monad on V then, for any object S of Kl T , the linear-use state monad Kl T (S, (−) · S) on V is also known as the application of the state monad transformer to T , as in [28].)

A coreflection. The constructions
Kl and St form a bi-adjunction between the 2categories of Kleisli models and of enriched models with state. One intuition for this is that it expresses the minimality property of Kleisli resolutions of monads. See Appendix C for a proof of Theorem 5.3. Since left bi-adjoints preserve bi-initial objects we get the following connection between the syntactic enriched model (V ecbv , C ecbv , S) and the syntactic Kleisli model (V fgcbv , C fgcbv , J). Since Kl(St(V, C, J)) = (V, Kl 1 , J 1 ) the unit of the adjunction can be described as the The pair (id V , G) preserves the enrichment only up to isomorphism, and this is our main motivation for using 2-categories of models (see also the discussion in Section 2.5).

5.4.
A semantic explanation of the state-passing translation. The linear-use statepassing translation is essentially the interpretation of fine-grain call-by-value into the model obtained by applying the construction Kl of Section 5 to the syntactic enriched call-by-value model of Section 2.4. In this model judgements Γ v V : σ and Γ p M : σ are interpreted as judgements of the form respectively, where Γ S is the product of all the types appearing in Γ S .
. . x n : σ n be a context of FGCBV and let Γ v V : τ and Γ p M : τ be judgements of FGCBV. Then V and M are interpreted as the equivalence classes of the terms Soundness of the state-passing translation (Theorem 4.1) follows immediately from Lemma 5.5. Fullness on types and full completeness (Theorems 4.2 and 4.3) are also consequences.
Proof of Theorems 4.2 and 4.3. By Theorem 3.3 and Lemma 5.5 the state-passing translation is the unique (up to isomorphism) 1-cell in Kleisli. It suffices to show that this is an equivalence in Kleisli, because this implies that F and G are both equivalences of categories, in particular they are essentially full on objects (proving Theorem 4.2) and full and faithful (proving Theorem 4.3).
By initiality (F, G) must be isomorphic to the composite of the unit of the adjunction (which is an isomorphism by Theorem 5.3) and Kl applied to the equivalence of Corollary 5.4. Since this composite is an equivalence, so is (F, G).

Sums
It is routine to add sum types to the languages considered in Section 2 and 3, and the state-passing translation extends straightforwardly. We now summarize the details.
6.1. Sums in the enriched call-by-value calculus. We add sums to the enriched callby-value calculus, for both value and computation types. The required modifications to the calculus are given in Figure 3. The resulting calculus is still a fragment of the enriched effect calculus [7]. We now extend the notion of model to accommodate the sums.
Terminology. Recall that a distributive category is a category with finite products and coproducts such that the canonical morphisms 0 → A × 0 and ( If a distributive category V has an action (·) on a category C with finite coproducts (0, ⊕), then we say that the situation is distributive if the four canonical morphisms 0 → A · 0, If the action is enriched, i.e. each functor (− · A) : V → C has a right adjoint, then this definition of distributive coproducts amounts to the usual notion of enriched coproducts. (Note that when the action is enriched then the third and fourth canonical morphisms are necessarily isomorphisms since left adjoints preserve colimits.) Definition 6.1. A distributive enriched model is given by a distributive category V and a category C enriched in V with copowers and enriched coproducts.
It is straightforward to extend the sound interpretation of the enriched call-by-value calculus in enriched models ( §2.2) to a sound interpretation of enriched call-by-value calculus with sums in distributive enriched models.
Of the examples in Section 2.3, (1)-(5) are distributive. The syntactic model of the version of the calculus with sums is a distributive enriched model, and it is bi-initial for the suitable generalization of morphism.
6.2. Sums in the fine-grain call-by-value calculus. It is equally straightforward to add sums to the fine-grain call-by-value language. This is summarized in Figure 4.
We only include constructors/destructors as value terms, but from these we can derive constructors/destructors for producer terms, as follows.
where w, z are fresh. These constructions have derived typing rules Γ p M : 0

Types.
A, B :: Term formation. The following rules are in addition to the rules in Figure 1.
Equality. The following rules are in addition to the rules in Figure 1.

Types.
σ : Term formation. The following rules are in addition to the rules in Figure 2.
Equality. The following rules are in addition to the rules in Figure 2. For example: We now refine the notion of Kleisli model (Def. 3.1) to accommodate the sums. is a distributive enriched model (Def 6.1) together with an identity-on-objects functor J : V → C that strictly preserves copowers and coproducts.
Note that in any Kleisli model, J will preserve coproducts because it has a right adjoint, C(1, −). We insist moreover that it preserves coproducts strictly.
Note It is straightforward to extend our interpretation of the fine-grain call-by-value calculus in Kleisli models ( §3.1) to an interpretation of the calculus with sums in distributive Kleisli models. The interpretation is sound and there is a syntactic model.
In Section 3.2 we discussed the equivalence between enriched Kleisli models and strong monads with Kleisli exponentials. This equivalence extends to an equivalence between distributive enriched Kleisli models, and strong monads on distributive categories with Kleisli exponentials. Likewise, the constructions St and Kl of Section 5 extend to constructions deriving distributive enriched models from distributive Kleisli models and vice versa, and an extension of Theorem 5.3 states that St and Kl exhibit a 2-category of distributive Kleisli models as a coreflective subcategory of a 2-category of distributive enriched models.
6.3. Sums and the state-passing translation. It is straightforward to adapt the statepassing translation to accommodate sums. Recall that each type σ of FGCBV is translated to a value type σ S of ECBV. We set We extend this translation to type contexts, taking an FGCBV type context Γ to an ECBV type context Γ S . Recall that the translation on terms takes an FGCBV value type judgement Γ v V : σ to an ECBV judgement Γ S | − V S : σ S , and takes an FGCBV producer judgement Γ p M : σ to an ECBV judgement Γ S | s : S M S s : !(σ S ) ⊗ S. We extend the translation in Section 4 straightforwardly, as follows: 2 ) The translation remains sound. The full definability results (Theorems 4.2 and 4.3) continue to hold in the presence of sums.

Remarks on the linear-use continuation-passing translation
We now briefly emphasise that the linear-use continuation-passing translation arises as a formal dual of the linear-use state-passing translation. This is not a new observation: Hasegawa noticed it in the context of classical linear logic ([15, §8], [33]) and indeed it informed the earlier work on the enriched effect calculus.
The linear-use continuation-passing translation was first elaborated by Berdine, O'Hearn, Reddy and Thielecke [4], but our main reference is the more recent work by Egger, Møgelberg and Simpson [9,10]. They showed that the linear-use continuation-passing translation can be extended to an involutive translation of the enriched effect calculus to itself, and derived a full completeness result from this. That work, in turn, stems from Hasegawa's full completeness result [15] for a linear-use continuation-passing translation into dual intuitionistic / linear logic.
Following [9], our development is fuelled by the following categorical observation. If a category C is enriched in V with copowers, then we can form the dual category C op which is also enriched in V, but now with powers instead of copowers. (Recall that an enriched category C has powers Y X if the functor Hom V (X, C(−, Y )) : C op → Set is
Equations: Equations of Figure 1 but with equations for tensor types replaced by: representable.) When viewed under this duality, the state-passing translation becomes the continuation-passing translation, as we now explain.
In Figure 5, we provide an internal language for enriched categories with powers. We call this the 'CPS variant of ECBV', because it is the target of the continuation passing translation (see below). The key difference with Figure 1 is that we have replaced the tensor type (!A ⊗ B) by a power type (A → B). It is another fragment of the enriched effect calculus. If V is a category with products and C is a category enriched in V with powers, then we can interpret this CPS variant of ECBV in (V, C) through a variation of the interpretation in Section 2.2. The power type is interpreted using the categorical powers: Following the categorical analysis above, we define a bijection (−) • between the types of ECBV with this CPS variant: This bijection extends to terms-in-context straightforwardly, and the resulting translation is a restriction of the linear-use cps involution of the enriched effect calculus studied in [9,10]. We achieve a linear-use continuation-passing translation by composing the state-passing translation of Section 4 with this bijection (7.1). For clarity, we now write this out explicitly. We fix a computation type R of ECBV, thought of as a return type. We translate FGCBV types σ to ECBV value types σ R : We extend this translation to type contexts, taking an FGCBV type context Γ to an ECBV type context Γ R . The translation on terms is syntax-directed. We pick a variable k, completely fresh. The translation takes an FGCBV value type judgement Γ v V : σ to an ECBV judgement Γ R | − V R : σ R , and it take an FGCBV producer judgement Γ p M : σ to an ECBV judgement Γ R | k : The continuation-passing translation inherits the following results from the soundness and full completeness of the state-passing translation (Theorems 4.1 and 4.3).
Proposition 7.1. For any computation type R, the continuation-passing translation is sound: , Corollary 1). Let R be a computation type constant. The continuationpassing translation is fully complete, in the following sense.
The full completeness result is the same as the one obtained by Egger et al. [ (For brevity, we omit the term language, which is a fragment of the enriched effect calculus.) The type system is designed to be dual to the enriched call-by-value language with sums. The translation from that language to this one (7.1) is extended as follows: and the analysis of Section 6.3 can be converted to a fully-complete linear-use continuationpassing style translation from fine-grain call-by-value with sums.

Effect theories
To illustrate the nature of the state-passing translation we endow our calculi with effects. We do this is in a general way, by following the programme of Plotkin, Power and others [38] whereby a theory of effects is presented as an algebraic theory.
We discuss how to add effects to the source and target languages of the state-passing translation, FGCBV and ECBV. Our central observation is that to accommodate an algebraic theory of effects in the enriched call-by-value calculus it is necessary and sufficient to supply the chosen state type S with the structure of a comodel. The idea of state being a comodel, particularly for the theory of store, arose in the work of Plotkin, Power and Shkaravska [40,35].
The section is structured as follows. We begin with an overview in which we study the situation for a particular algebraic effect. We then proceed to look at a general notion of effect theory ( §8.3), its relationship with the state-passing translation ( §8.4) and notions of model and comodel ( §8.5,8.6).
8.1. Overview. We give an overview of the situation in terms of a particular algebraic theory: an algebraic theory for accessing a single bit of memory. This is an algebraic theory in the classical sense (like monoids, groups, rings, etc.). It has one binary operation (?), a unary operation (f) and the following four equations: Here is some intuition. If x and y are computations, then x ? y is the computation that first reads the bit in memory and then branches to x or to y depending on whether the bit was set. If x is a computation then f(x) is the computation that first flips the bit in memory (0 to 1, 1 to 0) and then continues as x. There are derived operations update 0 (x) def = x ? f(x) and update 1 (x) def = f(x) ? x, which first write 0 (resp. 1) and then continue as x. We now explain how to accommodate this algebraic theory in the fine-grain and enriched call-by-value calculi. 8.1.1. Fine-grain call-by-value: algebraic operations and generic effects. In the fine-grain call-by-value calculus ( §3), the algebraic theory (8.1) can be accommodated in two equivalent ways: by adding algebraic operations and by adding generic effects. In adding the operations, we add the following term formation rules for each type σ: We also add the equations in (8.1) at each type, and an algebraicity equation for each operation (e.g. [43, Def 3.14]): τ The result is a programming language with higher types and a single bit of storage.
The second way to accommodate the algebraic theory into the fine-grain call-by-value calculus is by adding generic effects. For this we need sum types ( §6.2). The idea is that an expression in n variables in the algebraic theory corresponds to a ground producer term of type n (= 1 + · · · + 1). Thus we add the following axioms for term formation: Informally, deref( ) is a computation that returns the boolean value of the memory cell, and flip( ) is a computation that flips the value in the memory cell. An important observation of Plotkin and Power [38] is that the algebraic operations can be recovered at all types from the generic effects, as follows: where we use some shorthand notation: The two derived operations for writing a bit can be combined into a single command assign: ) then flip( ) else return ( ) : 1 where xor is the evident binary operation on values of type 2. Using this derived command, the four equations for accessing the bit of memory can be equivalently written as the three x : 2 p assign(x); deref( ) ≡ assign(x); return (x) : 2 (8.6) x, y : 2 p assign(x); assign(y) ≡ assign(y) : 1 (8.7) which state that reading a cell and then writing the same value is the same as doing nothing, that writing and the reading yields the value just written, and that the effect of two writes equals that of the second. (It is called a comodel because the arrows have been reversed and (×) has become (⊕).) Using the isomorphism (S ⊕ S) ∼ = (!2 ⊗ S), we can understand the type of (read) as S !2 ⊗ S. The idea is that the read operation takes a state and returns the value stored in that state. It also returns a state: this is necessary because state is linear and cannot be discarded or duplicated. Notice that, under the state-passing translation, the two generic effects (8.3) become the two state access operations.
The four equations (8.1) are also appealing when written in terms of state access operations. In Section 4 we have seen a fully-complete state-passing translation from FGCBV to ECBV. This translation extends to a fully-complete translation from FGCBV with generic effects to ECBV with state access operations. 8.1.3. Continuation passing style and algebraic operations. Finally, we turn to the linear-use continuation-passing style. In this setting, it is natural to require that the distinguished return type R be a model of the theory. This is dual to the situation with state-passing style, where the distinguished state type S is a comodel of the theory.

8.1.4.
Further simple examples of algebraic theories for computational effects. The theory of accessing a bit of memory is perhaps the simplest example of a stateful effect. The connections between algebraic operations, generic effects and state access operations also work for less state-like effects.
Printing. The algebraic theory of printing a single bit has two unary function symbols, p 0 and p 1 . For instance, the term p 0 (p 1 (x)) should be understood as the computation that first prints 0, then prints 1, then continues as x. There are no equations in this theory. The generic effects for printing can be grouped together into one producer term x : 2 p print(x) : 1 thought of as a command that prints its argument. As a state access operation, we have a function print : !2 ⊗ S S which, given a bit and a state, returns a new state. Intuitively, S is a list of everything printed so far, and print appends its first argument to its second argument.
Probability. There are different algebraic theories of probabilistic choice. The simplest one is the theory of 'mean-values' considered by Heckmann [16] (but perhaps first introduced by Aczél [2]): it has one binary function symbol and its axioms are the medial law, idempotence and commutativity: The idea is that a computation x y tosses a coin, and proceeds as x if heads and y if tails. The generic effect for is Γ p toss( ) : 2 which, intuitively, tosses the coin and returns the result. In this style, the first equation is written says that if you toss a coin it is the same as tossing a coin and turning it once more without looking. This illustrates that probability is not really stateful and so for this effect the approach based on algebraic operations is perhaps the most profitable perspective. The point is that different computational effects are better suited to different approaches (algebraic operations, generic effects, and state access operations) even though all three approaches are always available.

State access operations, algebraic operations, and generic effects.
We now make precise the informal connections made between state access operations, generic effects and algebraic operations in the previous section. We do this by revisiting the results of Plotkin and Power [38] in the context of an enriched model (V, C).
In the previous section we focused on the classical situation where arities are natural numbers. However, from the perspective of state access operations, generic effects and algebraic operations have little to do with natural numbers per se. It is just as easy to allow arities to be arbitrary objects of the base category V. In the following result we do not make an artificial restriction to natural numbers. Instead we consider an operation with arity [A 1 , . . . , A n ] and a parameter from B, where A 1 , . . . , A n , B are objects of V. The classical case of an n-ary operation is recovered by setting the objects A 1 , . . . , A n , B to all be the terminal object 1. (1) A state access operation: a morphism B · S → A 1 · S ⊕ . . . ⊕ A n · S in C.

(3) An algebraic operation: a V-natural family of morphisms in
The last point requires some explanation. First, even though V is not cartesian closed, exponentials with base U S (X) exist: (U S X) A ∼ = C(A · S, X). Second, the constructions can be understood as V-functors F, G : C → V, since there are families of morphisms in V that satisfy the laws for functors (respecting identities and composition). Thirdly, a family of morphisms {φ X : F (X) → G(X)} X∈C is called V-natural if the following diagram commutes in V for all X and Y : (It is perhaps more compelling if algebraic operations are defined as structure on a V-category of T S -algebras, but this V-category cannot be constructed without further assumptions on V -see [38, §7].) Proof of Theorem 8.1. To see the connection between (1) and (2), consider the following bijections: To see the connection between (1) and (3), we note that and the enriched Yoneda lemma gives We remark that the equivalence of (2) and (3) is essentially Theorem 2 of [38].

Effect theories.
In the previous section we described connection between state access operations, generic effects and algebraic operations. As we explained, the natural level of generality for this is more sophisticated than the classical setting: the arity of an operation is a list and we allow the operation to take a parameter. This suggests a generalization of algebraic theories that we call 'effect theories', since they are useful from the computational perspective.
The illustration in Section 8.1 involves storage of a single bit. A motivating example of effect theory arises from modifying that theory above to allow storage of a more interesting datatype. In FGCBV, we would like to have an (abstract) type Val of storable values, and generic effects deref and assign with typing judgements We add to the theory of equality for FGCBV (Fig. 2) the three equations for global store proposed by Plotkin and Power [37] (8.5-(8.7)): p return ( ) ≡ deref( ) to x. assign(x) : 1 x : Val p assign(x); deref( ) ≡ assign(x); return (x) : Val x, y : Val p assign(x); assign(y) ≡ assign(y) : 1 Our notion of effect theory accommodates the classical kinds of theory in the overview ( § 8.1) and also the more general kind of theory of memory access illustrated above. It is roughly the same as that used by Plotkin and Pretnar [36, §3]. The main difference is in the presentation: we use generic effects rather than algebraic operations. Rather than introducing a new calculus for expressing the allowable equations of an effect theory, we use the first-order fragment of FGCBV.
Value theories. Before we introduce effect theories we briefly discuss value theories, which are simple extensions of the value judgements of FGCBV. By a value signature we shall simply mean a signature for a many-sorted algebraic theory in the usual sense. This means a set of type constants ranged over by α, β, and a set of term constants f with a given arity f : (α 1 , . . . , α n ) → β, where the α i , β range over type constants. We can extend FGCBV along a value signature by adding the type constants and the typing rule  Figure 6. This notion of 'effect theory' is connected with the classical notion of algebraic theory in Section 8.1 as follows. If the value theory is empty, with no type constants (α) and no function symbols, then the lists of type constants in (8.12) must all empty, and each generic effect is an operation of arity n. This is the generic effect presentation of an algebraic theory as described in Section 8.1.1.

Types.
σ, τ : Terms. The grammar for terms is as follows. Typing judgements are in Figure 2, Figure 4, and Equations (8.11) and (8.12). Figure 6: The sub-calculus of fine-grain call-by-value that is used for describing effect theories 8.4. Effect theories and the state-passing translation. An effect theory is an extension to the fine-grain call-by-value language. In Section 4 we explained how the linear-use statepassing translation goes from FGCBV to ECBV. We now explain how ECBV needs to be extended to support this state-passing translation. The restricted nature of the effect theories makes this particularly straightforward and illuminating. Value theory: • For each type constant in the value theory, we assume a value type constant.
• For each term constant f :ᾱ → β in the value theory we add the following term formation rule: Γ | s : S M S s ≡ N S s : !τ ⊗ S. Notice that we do not need to translate the types in Γ because equations in an effect theory must be from the first-order fragment of fine-grain call-by-value (Fig. 6) which is shared with enriched call-by-value. For instance, the equations in the effect theory for reading/flipping a bit (8.4) give rise to the equations on the state object (8.9 As another example, (return V ) We now return to the setting of classical algebra, when the value theory has no type constants or value constants. We will show that models in the above sense are models of algebraic theories in the classical sense. If there are no type constants then every type in the effect language ( Figure 6) is isomorphic to one of the form 1 + 1 + · · · + 1. The arity of an effect constant e :β;ᾱ 1 + . . . +ᾱ n must compriseβ as the empty list (since there are no type constants) andᾱ 1 + . . . +ᾱ n must be a sequence of n empty lists. Thus the interpretation of e in the model is a morphism [[e]] : R n → R.
We now explain the nature of equations in this restricted setting. In what follows, we will write a natural number n for the type that is the n-fold sum of 1. We will write in i ( ) for the ith injection of type n, where 1 ≤ i ≤ n, and we will make use of n-ary case constructions, case V of (in 1 ( ).W 1 | . . . |in n ( ).W n ) to destruct terms V of type n. These are just syntactic shorthand for terms that can be defined in the language in Figure 6.
We can focus on equations where Γ is empty. This is because every context has a finite number of ground valuations -if a variable x in a context has type n, then it could be valued with in 1 ( ) . . . in n ( ) -and, moreover, an effect equation Γ p M ≡ N : n is satisfied if and only if it is satisfied at each ground instantiation. The next step is to note that every effect term − p M : 1 + 1 · · · + 1 is equal to one built from the following rules: Thus we see that, in the situation where there are no type constants or value constants, the new general notion of model is the classical notion of model for an algebraic theory.
8.6. Examples of set-theoretic models and comodels. We revisit the simple example effect theories from Sections 8.1 and 8.3 from the model-theoretic perspective. In each case, we find that there are comodels that are state-like.
8.6.1. Storage. The category Set is enriched in itself with copowers given by products and the enrichment given by the function space. The set 2 = {0, 1} is a comodel for the theory of accessing a bit of memory ( §8.1), with read(x) = (x, x) and flip(x) = ¬x. This is a comodel for the theory in the enriched model (Set, Set). Power and Shkaravska [40] showed that 2 is the final comodel in Set for the theory of accessing a bit of memory.
As an aside, we note that Set is actually equivalent to the category of models for the theory of accessing a bit of memory. The theory of reading a bit of memory is sometimes called the theory of 'rectangular bands' because every model is isomorphic to one of the form X × Y , with (x, y) ? (x , y ) def = (x, y ). The anti-involution operation (f) enforces that the model is isomorphic to one of the form X × X, and thus determined by a single set. This phenomenon has been investigated in a more general setting by Métayer [30] and Mesablishvili [29].
We can consider set theoretic models of the theory of storing an abstract datatype (8.10). What is needed is an interpretation Val of the value sort, which also plays the role of the state object. We let read(x) = (x, x) and write(v, s) = v. This is a comodel for the theory for store in the enriched model (Set, Set).
In both cases, the induced monad on Set is the store monad ((−) × S) S . 8.6.2. Printing. Let 2 * -Act be the category of algebras for the theory of printing a bit. The objects are triples (X, p 0 , p 1 ) where p 0 , p 1 : X → X, and the morphisms (X, p X,0 , p X,1 ) → (Y, p Y,0 , p Y,1 ) are functions X → Y that commute with the operations. As any ordinary category, this category is enriched in Set. It has copowers given by Thus (Set, 2 * -Act) is an enriched model. The algebra structure of each algebra equips it with the structure of a comodel in the category of algebras. The leading example is the set 2 * of strings over {0, 1}, with p 2 * ,i (s) = si. The induced state monad 2 * -Act(2 * , (−) · 2 * ) is isomorphic to the monad 2 * × (−) on Set. We can understand a string in 2 * as a state: it is the list of things output so far. 8.6.3. Probability. Let MVAlg be the category of mean-value algebras. The objects are pairs (X, ) of a set X and a binary operation satisfying the laws of mean-value algebras ( §8.1.4). The pair (Set, MVAlg) is an enriched model.
The one-element set is trivially a mean-value algebra, and it can be given the structure of a comodel in the category of mean-value algebras. We can understand the one-element set as a set of states: this captures the idea that probability is a stateless notion of computation. Nonetheless, this 'state object' induces a 'state monad' on Set. This can be understood as a monad D of finite dyadic probability distributions. By a finite dyadic probability distribution on a set X, we mean a function p : X → [0, 1] such that supp(p) = {x ∈ X | p(x) = 0} is finite, x∈supp(p) p(x) = 1, and for all x, p(x) has a finite binary representation. The monad D has D(X) as the set of all finite dyadic probability distributions; the unit picks out the Kronecker distributions, and multiplication µ X : D(D(X)) → D(X) takes a distribution p : D(X) → [0, 1] on D(X) to a distribution µ X (p) : X → [0, 1] on X, given by ). In general, when the state object is a terminal object then the induced monad preserves terminal objects. A terminal-object-preserving monad is sometimes called affine [25, Thm. 2.1] and the corresponding effects are said to be discardable (e.g. [12], [47,Def. 4.2.4]) since the following rule is admissible in the fine-grain call-by-value language.
Relating notions of (co)model for effect theories. We now extend Theorem 8.1 to show, for each effect theory E, a bijective correspondence between the following: comodel structures on S, interpretations of E in the Kleisli model (V, Kl S , J S ), algebraic operations equipping each U S X with a model structure for E. The latter notion requires some explanation, because the definition of model given in Section 8.5.4 defines only what it means for R in a category C to be a model of E if (V, C op ) is an enriched model, and in the setting of Theorem 8.1 V op is generally not V-enriched.
To generalize the notion of model, let V be a distributive category, let R be a fixed object of V such that all exponents of the form R A exist (i.e. V(− × A, R) is representable for all A) and let an interpretation of the value theory of E be given. We define a model structure for E on R to be an interpretation of E in the Kleisli model (V,  Proof. We first prove equivalence of (1) and (2). First note that in both cases, an effect constant e :β;ᾱ 1 + . . . +ᾱ n is modelled as a morphism . We just show that these are well-defined on objects. The case of Kl is simply the implication from (1) to (2) of Theorem 8.2.
In the case of St we must show that 1 carries a comodel structure for E whenever (V, C, J) models E. An effect constant e :β;ᾱ 1 + . . . +ᾱ n can be modelled as the composite where [[e]] refers to the interpretation of e in the given E-model structure of (V, C, J). We must show that this defines a comodel, i.e., that the equations are satisfied. To this end one can prove that for any term Γ p M : σ of the fragment of fine-grain call-by-value used for effect theories ( Figure 6

Relationship with Atkey's parameterized monads
Atkey's work on parameterized monads [3], has proven relevant to functional programming (e.g. [24, §5.2]). In this section we show that parameterized monads are essentially the same as enriched models.
Recall that, in general category theory, if a functor F : A × S → B is such that Conversely, suppose we are given an enriched model (V, C) and a chosen subcategory S of C. We define a parameterized monad T : It is routine to check that the two constructions are mutually inverse, up-to equivalence of categories.

Relationship with the enriched effect calculus
Our enriched call-by-value calculus (ECBV) is a fragment of the enriched effect calculus (EEC, [8,7]) which was designed to analyze linear usage in effectful computation. We now show that ECBV is not only a syntactic fragment of EEC: every model of the enriched call-by-value calculus embeds in a model of the enriched effect calculus.
The enriched effect calculus extends the enriched call-by-value calculus that we introduced in Section 2 with some type constructions: Full EEC [8] The additional types are: products (A × B) and powers (A → B) of computation types; an operation to coerce a value type A into a computation type !A; a space of pure functions (A → B) between value types; and an implicit inclusion of computation types as value types. These additional types have been used to describe other aspects of effectful computation. We briefly considered a linear-use CPS translation in Section 7, based on [9,10], for which we needed products and powers of computation types. Egger et al. [8] also describe monadic call-by-name and call-by-value interpretations, for which they use the coercion of value types into computation types and the implicit inclusion of computation types in value types.
The additional types of EEC do not affect the full completeness of the linear state-passing translation (Thm. 4.3), for the following reason. In Theorem 10.2 we show that every model of ECBV embeds in a model of EEC; conservativity of EEC over ECBV then follows from a strong normalisation result for EEC [7]. Thus the linear-use state-passing translation of Section 4 can be understood as a fully complete translation into EEC.
Definition 10.1. A closed enriched model is a pair of categories (V, C) such that V is cartesian closed with coproducts and C is V-enriched with powers and copowers and products and coproducts.
A model of EEC (V, C, F, U ) [8] is a closed enriched model (V, C) together with a V-enriched adjunction F U : C → V.
We refer to [8] for the term calculus and interpretation of EEC in EEC models. Here, we will analyze how the notion of EEC model compares to the other notions of model that we have discussed so far. One simple observation is that every closed enriched model is a distributive enriched model in the sense of Definition 6.1. Another observation is that the adjunction part of an EEC model can be equivalently given by a 'state' object of C (see [ Proof. The difference between enriched models and closed enriched models is that in an enriched model (V, C) the value category V need not be cartesian closed nor have coproducts, and the computation category C need not have coproducts, products and powers.
We use the Yoneda embedding to embed an enriched model in a closed enriched model For any small category A we consider the category A of contravariant functors, A op → Set, and natural transformations between them. The Yoneda embedding A → A(−, A) is a functor y A : A → A that exhibits A as a cocompletion of A. That is: A is cocomplete, with colimits computed pointwise, and for any other cocomplete category B and any functor F : A → B there is a colimit-preserving functor F ! : A → B given by where (y A ↓ P ) is the category of elements of P ; this colimit-preserving functor is essentially unique such that F ∼ = F ! · y A . Let (V, C) be an enriched model. We will show that ( V, C) is a closed enriched model, and that (V, C) embeds in it as an enriched model. We proceed by considering the following 2-categorical situation. Because the construction (−) is a free cocompletion, it can be understood as a weak 2-functor from the 2-category Cat of small categories, functors and natural transformations to the 2-category Cocomp of categories with all colimits, colimit-preserving functors and natural transformations.
In fact it is necessary to be slightly more general than this: we will understand Cat and Cocomp as 2-multicategories. Recall that a 2-multicategory is a Cat-enriched multicategory. So it is like a 2-category except that the domains of the 1-cells are sequences of objects. i.e. a functor F ! : A 1 × · · · × A n → B which preserves colimits in each argument. This construction is done by iteratively applying the following idea. If an n-ary functor preserves colimits in each of the first (k − 1) arguments, and A k is small, then there is an n-ary functor G !k : (A 1 , . . . , A k , . . . , A n ) → B that preserves colimits in each of the first k arguments such that G ∼ = G !k · (A 1 , . . . , y A , . . . , A n ). This is because the n-ary functor G : (A 1 , . . . , A n ) → B can be curried to a functor A k → Cocomp(A 1 , . . . , A k−1 ; Cat(A k+1 , . . . , A n ; B)) whose codomain is cocomplete, and which can thus be extended to a colimit-preserving functor using the universal property ofÂ k : A k → Cocomp(A 1 , . . . , A k−1 ; Cat(A k+1 , . . . , A n ; B)); this can be uncurried to give G !k : (A 1 , . . . , A k , . . . , A n ) → B. Ultimately, the extension F ! : A 1 × · · · × A n → B satisfies the following coend formula: • Recall the following consequence of the special adjoint functor theorem: a morphism F : ( A 1 , . . . , A n ) → B in Cocomp can be equivalently described as a functor that has a right adjoint in each argument, i.e. a right adjoint for each functor F (P 1 , . . . , − i , . . . , P n ) : A i → B. • Aside from size issues, there is a forgetful morphism of 2-multicategories Cat → Cocomp and (−) is left biadjoint to it. The Yoneda embedding is the unit for this adjunction. With the general situation explained, the proof of Theorem 10.2 is straightforward. We begin by considering the evident notion of 'weak monoid' in a 2-multicategory K. This comprises an object M of K and two 1-cells: m : (M, M) → M and e : () → M, with three coherence 2-isomorphisms. A morphism of 2-multicategories K → K takes weak monoids in K to weak monoids in K . In particular a monoidal category is a weak monoid in Cat, and the construction (−) takes it to a weak monoid in Cocomp, which is a cocomplete biclosed monoidal category. The Yoneda embedding M → M preserves the weak monoid structure. This is Day's convolution construction [5,17].
In particular, the value category V of our enriched model has products and this exhibits it as a monoidal category. It follows that V is cartesian closed and that the Yoneda embedding V → V preserves the product structure in V. Given a weak monoid M in a 2-multicategory K, we consider the evident notion of weak action for M: an object A of K and a 1-cell (M, A) → A satisfying the laws of monoid actions up-to coherent isomorphism. A morphism of 2-multicategories takes weak monoid actions to weak monoid actions. In particular, given a monoidal category M, an action of M on another category A induces an enrichment of A in M with powers and copowers. The Yoneda embedding A → A preserves the monoidal action. Moreover since it is 2-natural it preserves any enrichment or powers that already exist in A.
In particular, in our enriched model, V acts on C and so C is enriched in V with powers and copowers, and the Yoneda embedding C → C is enriched in V and preserves copowers.
The crux of the proof is that the Yoneda embedding adds closed structure -cartesian closed structure and powers -while preserving the other structure. Although the Yoneda embedding does not freely add the closed structure, it is considerably simpler that the free closure. This is one reason why Yoneda embeddings are a common technique in semantics. For instance, the enriched Yoneda embedding is used by Egger et al. [8] to show that Levy's call-by-push-value embeds in the enriched effect calculus (but the enriched Yoneda embedding is not appropriate in our proof because it does not preserve copowers).
Theorem 10.2 explains that EEC is conservative over ECBV, but it neglects sum types. Sum types play an important role in the study of generic effects and state access operations ( §8). We now show that EEC is conservative over ECBV with sum types. Proof. Our proof of Proposition 10.3 follows the same outline as our proof of Theorem 10.2. We must modify that proof because the Yoneda embedding y A : A → A does not preserve coproducts. We use the following variation on the Yoneda embedding. For any category A with finite coproducts, let FP(A op , Set) be the category of finite-product-preserving functors A op → Set and natural transformations between them. Assuming A has coproducts, the category FP(A op , Set) has coproducts too. The Yoneda embedding A → A(−, A) is a functor A → FP(A op , Set) which preserves coproducts. In fact, the Yoneda embedding exhibits FP(A op , Set) as the cocompletion of A as a category with finite coproducts. The category FP(A op , Set) is cocomplete (although not all colimits are computed pointwise), and for any coproduct-preserving functor F : A → B into a cocomplete category B there is a colimitpreserving functor F ! : FP(A op , Set) → B given by F ! (P ) this colimit-preserving functor is essentially unique such that F ∼ = F ! · y A (see e.g. [21,Thms 5.86,6.11], [42], [11]). Since a distributive enriched model has coproducts, this is the right variation of the Yoneda embedding to use.
We now mimic the proof of Theorem 10.2, replacing the cocompletion construction (−) with the cocompletion FP((−) op , Set) of a category with coproducts. Consider the 2-multicategory Coprod: the 0-cells are small categories with finite coproducts; the 1-cells F : (A 1 , . . . , A n ) → B are functors F : A 1 × · · · × A n → B that preserve coproducts in each argument; the 2-cells are natural transformations. The construction FP((−) op , Set) extends to a morphism of 2-multicategories from Coprod to Cocomp. By the special adjoint functor theorem, a morphism (FP(A op 1 , Set), . . . , FP(A op n , Set)) → B in Cocomp is a functor that has a right adjoint in each argument.
A weak monoid M in Coprod is a distributive monoidal category, i.e., a monoidal category with coproducts such that the tensor preserves coproducts in each argument. The construction FP(− op , Set) takes it to a weak monoid in Cocomp, which is a cocomplete biclosed monoidal category. The Yoneda embedding M → FP(M op , Set) preserves the weak monoid structure and coproducts.
In particular, if (V, C) is a distributive enriched model then V has distributive products and this exhibits it as a distributive monoidal category. It follows that FP(V op , Set) is cartesian closed with coproducts and that the Yoneda embedding V → FP(V op , Set) preserves the coproduct and product structure in V.
An action of a weak monoid in Coprod is the same thing as a distributive action in the sense of Section 6.1. Given a distributive monoidal category M, a distributive action of M on a category A with finite coproducts induces an enrichment of FP(A op , Set) in FP(M op , Set) with powers and copowers. The Yoneda embedding A → FP(A op , Set) preserves coproducts and the monoidal action. Moreover since it is 2-natural it preserves any enrichment or powers that already exist in A.
In particular, if (V, C) is a distributive enriched model then V acts on C, and so FP(C op , Set) is enriched in FP(V op , Set) with powers and copowers, and the Yoneda embedding C → FP(C op , Set) is enriched in V and preserves coproducts and copowers.
The construction in this proof is related to the following natural situation. Let Set f be the category of finite sets, and let T be a Lawvere theory. Then (Set f , T op ) is almost an enriched model, except that the category T op is typically not Set f -enriched. Nonetheless, our construction applied to (Set f , T op ) yields the basic motivating example of an EEC model: FP(Set op f , Set) is the category of sets (since Set f is the free category with finite coproducts on one generator) and FP(T, Set) is the category of algebras of the Lawvere theory. (See also [41,Thm. 38].) A.1. The 2-category Enr of enriched models. We first define a notion of morphism of enriched call-by-value model and transformations between these. This gives a 2-category Enr. Let (V, C) and (V , C ) be enriched call-by-value models (Def. 2.1). A morphism from (V, C) to (V , C ) is a triple (F, G, λ) such that F : V → V and G : C → C are functors, and λ is a natural family of isomorphisms The following three conditions must be satisfied: • F preserves products (up to isomorphism). • The following two coherence diagrams commute • The mate of λ −1 is an isomorphism F (C(B, C)) ∼ = C (GB, GC) Recall that the mate of λ −1 is the adjoint correspondent of A.4. Sums. The category dEnr is defined to have distributive enriched models as objects, 1-cells as in Enr with the restriction that F and G must both preserve coproducts, and 2-cells as in Enr. The definitions of the 2-categories Ecbv and Kleisli extend to 2-categories dEcbv and dKleisli of distributive enriched models with state objects and distributive Kleisli models.
A.5. Effect theories. We now explain how to extend the 2-categories to models that support effect theories, expanding on Section 8.8. We first define what it means for a functor to preserve a value theory.    Uniqueness is proved by induction on types.
Bi-initiality of the syntactic model (Theorem 2.4) follows from Lemma B.1 as follows. Given any other model, the unique morphism is given by interpretation of the syntax. To prove uniqueness, suppose (F, G, δ) is a 1-cell from dEcbv E to (V, C, S). Then Lemma B.1 gives the natural isomorphism: since interpretation in the syntactic model of terms with one variable is simply the identity, diagrams (A.1) prove naturality of the isomorphism. The required commutative diagrams (A.3) for 2-cells follow directly from definitions. has components given by F π 1 , F π 2 · S : F (A × B) · S → (F (A) × F (B)) · S On 2-cells we define Kl(β, γ) = (β, Kl(β, γ)) where Kl(β, γ) is the natural transformation whose components are Kl(β, γ) A = β A · S : F A · S → F A · S . Note that this defines a morphism in Kl S from Kl(F, G)(A) = F A to Kl((F , G ))(A) = F A as required.
The third component of η should be a natural transformation H(A · B) → A · Kl HB. Since both sides are equal to A × B it makes sense to take the identity transformation.