Cartesian effect categories are Freyd-categories

Most often, in a categorical semantics for a programming language, the substitution of terms is expressed by composition and finite products. However this does not deal with the order of evaluation of arguments, which may have major consequences when…

Authors: Jean-Guillaume Dumas, Dominique Duval, Jean-Claude Reynaud

Cartesian effect categories are F reyd-categories Jean-Guillaume Dumas ∗ Dominique Duv al † Jean-Claude Reynaud ‡ June 12., 2009 Abstract Most often, in a categorical semantics for a programming language, th e substitution of terms is expressed by composition and finite pro duct s. How ever this do es n ot deal with th e order of eva luation of argumen ts, which ma y h ave ma jor consequences when there are side-effects. In this pap er Cartesian effect categories are introdu ced for solving this issue, and they are compared with strong monads, F reyd- categories and Haskell’s Arrows. It is prov ed that a Cartesian effect category is a F reyd- category where the premonoidal structure is provided by a kind of binary p rod u ct, called the sequential pro duct. The universal prop erty of the sequential pro du ct pro vides Cartesi an effect categories with a p ow erful tool for constructions and pro ofs. T o our kn o wledge, b oth effect categories and sequential pro ducts are new notions. Keywords. Categorica l logic, computational effects, monads, F re yd-categories, premonoidal cate- gories, Arrow s, sequ entia l pro duct, effect categories, Cartesian effect categories. 1 In tro duction A categor ical s e mantics for a prog ramming language usually ass o ciates an ob ject to each type, a morphism to e a ch term, and uses co mp os ition a nd finite pro ducts for dealing with the substitution of ter ms. This framework behaves v ery well in a simple equational setting, but it has to b e adapted as so on as there is so me kind of computational effects, for instance non-termination or state updating in an imp erative langua ge. Then ther e are t wo kinds o f ter ms: the g e neral ter ms may cause effects while the pur e terms are e ffect-free. F ollo wing (Moggi, 19 91), a general term ma y be seen as a pr o gr am that returns a value which is pur e. In this pap er we fo cus on the following se quentiality issue: the catego rical pro ducts do not deal with the order of ev aluation of the ar guments, although this or der may have ma jor consequences when there are s ide - effects. F or solving this sequentialit y issue, we introduce Cartesian effe ct c ate gories as a n alter native for Cartesia n categorie s. Other approa ches include str ong monads (Moggi, 1989), F reyd-categ ories (P ow er and Robinson, 1997) and Arrows (H ughes, 200 0). T hes e frameworks are quite similar from several p oints o f view (Heunen and Jacobs, 2006; Atk ey, 2008), while our framework is more pr ecise. A first dra ft for Ca rtesian effect ca tegories can be found in (Dumas et al., 2007), and a s imila r a pproach in (Duv al and Reynaud, 200 5). A category is called Ca rtesian if it has finite pro ducts, and a sub categor y C of a categ ory K is ca lled wide if it ha s the s ame ob jects as K . A F r eyd-c ate gory is a gener alization of a Cartesian catego r y that consists essentially in a category K with a wide subcatego r y C , suc h that C is Cartesian (hence C is symmetric monoidal) and K is symmetric pr emonoidal. A Cartesian effe ct c ate gory , a s defined in this paper, is more precise a nd more homogeneous than a F reyd-catego ry: like the symmetric mono idal structure o n C deriv es ∗ Laboratoire Jean Kuntzmann, Uni v ersit´ e de Grenoble, 38041 Grenoble, F rance – Jean-Guillaume.Dumas@imag.fr – h ttp://ljk.imag.fr/membres/Jean-Guillaume.Dumas † Laboratoire Jean Kun tzmann, Unive rsit´ e de Grenoble, 38041 Grenoble, F rance – Domi nique.Duv al@im ag.fr – h ttp://ljk.imag.fr/membres/Dominique.Duv al ‡ Malhivert, 38640 Claix, F r ance – Jean-Claude.Reynau d@imag.fr 1 from its pro duct, in a Cartesian effect catego ry the symmetric premono idal structur e on K derives from some kind of pro duct, called a se quential pr o duct , which extends the pro duct of C and g eneralizes the usual categoric al pro duct. In fact, there are tw o steps in our definitio n. First an effe ct c ate gory is defined, without men tioning any kind of pro duct: it is made of a category K with a wide sub catego ry C and with a r elation ⊳ called c onsist en cy b etw e e n morphisms. Then a Cartesian effe ct c ate gory is defined as an effect category with a binary pro duct o n C e xtended by a se quential pr o duct on K , which itself is defined thanks to a universal prop erty that generalizes the categor ical pro duct prop er ty and inv olves the co nsistency r elation. Like e very universal prop erty , this provides a p owerful to ol for constructio ns and pro ofs in a Ca rtesian e ffect categor y . Let us lo ok a t tw o basic ex a mples of effect ca tegories (tw o mor phisms in a category a re ca lled parallel if they share the sa me do ma in a nd the sa me co domain). The n on- termination e ffect inv olves par tial functions . As usual, tw o partial functions are called c onsist ent when they coincide on the intersection of their domains of definition. Thu s, on the one hand, tw o partial functions f and f ′ are consis ten t if a nd o nly if there is a tota l function v such that v is co nsistent b oth with f and with f ′ . On the o ther hand, let us say that t w o partial functions hav e the same effe ct if they have the sa me domain of definition. Then clear ly , tw o partia l functions have the sa me effect and ar e cons istent if and only if they are equal. In an imper ative progra mming language, there are side-e ffects due to the mo dification o f the state , since the functions in the sense of the pro g ramming language, in addition to hav e arguments and a return v alue, are allow ed to use the state and to mo dify it. A function is called pur e if it ne ither use nor mo dify the state, and the side-effects are due to the no n-pure functions. Let us say that a function f is c onsistent with a pure function v when b oth r eturn the sa me v alue when they are g iven the sa me arg ument s. Then tw o arbitr a ry functions are called c onsistent when they a re consistent with a common pure function, whic h means that bo th return the same v alue when they are g iven the s ame arg umen ts a nd that in addition this v alue does not depend on the state. It sho uld b e noted tha t this c onsistency relatio n is no t r eflexive. Ther efore, if tw o functions hav e the sa me e ffect and are consistent then they are equa l, but the conv erse is false . More generally , an effe ct c ate gory is a catego ry K with a wide subcatego ry C and with a consistency relation ⊳ betw een parallel morphisms, the first one in K and the s econd one in C , sa tis fying a form of compatibility with the compos itio n. The morphisms in C are called pur e and are denoted with . Two morphisms in K are ca lled c onsistent when there is a pure morphism v such that f ⊳ v a nd f ′ ⊳ v ; this is denoted f ⊳ ⊲ f ′ , and the prop erties of consistency are suc h that the relation ⊳⊲ extends ⊳ . Let 1 be a terminal o b ject in C , the effe ct of a morphism f is defined as the mo rphism E ( f ) = h i Y ◦ f wher e h i Y is the unique pure morphism h i Y : Y 1. It is assumed that the following c omplementarity prop erty holds, which mea ns that the consistency r elation is a kind of “up-to-effects” r e la tion: if t w o morphisms ha v e the same effect and a re co nsistent, then they ar e equal. This notion of consistency coincides with the usual one for partia l functions, but to o ur knowledge it is new in the gener al setting of computational effects. F or instance, we will see in section 2.6 that it is fairly different from the no tio n of having the same re sult that is defined in (Mogg i, 199 5) in the framework of ev aluation logic. Let us lo ok mor e closely at the complemen tarity pro p e rty (for s ome fixed domain and co domain). On the one hand, to ha ve the s ame effect is an e q uiv alence relation ≈ with one distinguishe d equiv alence class, the clas s of the morphisms without effect, which contains all the pure mor phisms. On the other hand, to b e consisten t is a symmetric r elation ⊳ ⊲ , with each maxima l clique made of a unique pure morphism and all the morphisms that are consistent with it. The co mplement arity pr o p erty a sserts that there is a t most one morphism in the in tersection of a given equiv alence class for ≈ and a given maxima l clique for ⊳⊲ . A binary pro duct on a category C provides a bifunctor × on C such that for all v 1 : X 1 → Y 1 and v 2 : X 2 → Y 2 , the morphism v 1 × v 2 : X 1 × X 2 → Y 1 × Y 2 is characterized by the following diagram, where the p i ’s a nd q i ’s are the pr o jections. This prop erty is symmetric in v 1 and v 2 . When C is the categor y of sets, this means that ( v 1 × v 2 )( x 1 , x 2 ) = h v 1 ( x 1 ) , v 2 ( x 2 ) i . 2 X 1 v 1 / / = Y 1 X 1 × X 2 v 1 × v 2 / / p 1 O O p 2   Y 1 × Y 2 q 1 O O q 2   X 2 v 2 / / Y 2 = A Cartesian effe ct c ate gory is defined as an effect ca tegory with a binary pro duct on C , extended b y t wo symmetric semi-pur e pr o ducts v ⋉ f and f ⋊ v wher e v is pur e. The left semi-pure pro duct v ⋉ f is characterized b y the following diagra m, which means that q 1 ◦ ( v ⋉ f ) ⊳ v ◦ p 1 and q 2 ◦ ( v ⋉ f ) = f ◦ p 2 (the right semi-pure pro duct is characterized by a s ymmetric diagra m). Y 1 v / / /o /o /o /o /o /o /o /o ⊳ Y 1 Y 1 × X 2 v ⋉ f / / p 1 O O O p 2   O Y 1 × Y 2 q 1 O O O q 2   O X 2 f / / Y 2 = This pr op erty mea ns that the effect of v ⋉ f is the effect of f , and that “up to effects” v ⋉ f looks like an or dinary binary pro duct. Then the le ft se qu en tial pr o duct of t wo a rbitrary morphisms f 1 and f 2 is eas ily obtained by co mpo sing tw o semi- pur e pro ducts: f 1 ⋉ f 2 = (id 1 ⋉ f 2 ) ◦ ( f 1 ⋊ id 2 ) where id 1 and id 2 denote the ident ities of Y 1 and X 2 , resp ectively . T his definition formalizes the notion of s e quentiality : “firs t f 1 , then f 2 ”. The right sequential pro duct is defined in a symmetric wa y . W e will chec k tha t the sequential pro duct extends the semi-pure pro duct, so that there is no ambiguity in using the same symbols ⋉ and ⋊ fo r b oth. This approa ch, to o ur knowledge, is co mpletely new. It can b e s umma r ized as follows: while the universal prop erty o f a binary pro duct consists in t wo equalities , the universal pr op erty o f a semi-pure pro duct consists in one equality a nd one consistency . F or instance, in the category of s ets with partial functions, v ⋉ f is the partial function suc h th at ( v ⋉ f )( x 1 , x 2 ) = h y 1 , y 2 i where y 1 = v ( x 1 ) and y 2 = f ( x 2 ) whenever f ( x 2 ) is defined, otherwise ( v ⋉ f )( x 1 , x 2 ) is not defined. When side-effects ar e due to the up da ting o f the state, v ⋉ f is such that for each state s , ( v ⋉ f )( s, x 1 , x 2 ) = h s 2 , y 1 , y 2 i where h s, y 1 i = v ( s, x 1 ) and h s 2 , y 2 i = f ( s, x 2 ). The prop er ties o f the sequential pro duct imply that a Cartesia n e ffect category is a F rey d-categor y . On the other hand, each stro ng monad defines a F reyd-catego r y (Po wer and Robinson, 1997). W e prov e that a F reyd-c ategory defined from a strong monad is a w eak Cartesian effect catego ry if and only if, ro ughly sp eaking: the strength of the monad is consistent with the identit y . Section 2 is dev oted to effect categories a nd section 3 to Cartesian effect categor ies. Then Car tesian effect categ o ries a re related to F r eyd-catego ries, Arr ows a nd strong monads in section 4. Several exa mples are consider ed in se c tio ns 2.5, 3.8 and 4.4. 2 Effect categories 2.1 Pure morphisms Definition 2.1 . A sub categ ory C of a c ategory K is wide if it ha s the same ob jects as K ; this is denoted C j K . Given C j K , a morphism of K is called pur e if it is in C ; then it is denoted with “ ”. An ob ject 1 is a pur e terminal ob ject in C j K if it is terminal in C , then fo r each o b ject X the unique pure morphism from X to 1 is denoted h i X : X 1. R emark 1 . Pure morphisms i n a Kle i sli category . Let C 0 be a categ ory (called the ba s e category) with a mona d ( M , µ, η ) (or simply M ) and let K M be the Kleisli category of M . Then K M has the same ob jects as C 0 and for all ob jects X and Y ther e is a bijection betw e en C 0 ( X, M Y ) a nd K M ( X, Y ). In this pap er, for each morphism f : X → Y in K M the corr esp onding morphism in C 0 is denoted [ f ] : X → M Y , and we 3 say that f stands for [ f ], and for ea ch morphism ϕ : X → M Y in C 0 the corres po nding morphis m in K M is denoted ] ϕ [: X → Y . So, ]([ f ])[= f f or every f in K M and [(] ϕ [)] = ϕ for every ϕ in C 0 with co doma in M Y for so me Y . Let J : C 0 → K M denote the functor asso ciated with M a nd let C M = J ( C 0 ). Then J is the identit y o n ob jects, so that C M is a wide subcateg ory o f K M . A pure morphism v : X Y in K M is a morphism v = J ( v 0 ) for some v 0 : X → Y in C 0 ; this means that [ v ] = η Y ◦ v 0 : X → M Y in C 0 . Ea ch ident ity id X in K M henceforth stands for [id X ] = η X and the c omp osition g ◦ f of f : X → Y and g : Y → Z stands for [ g ◦ f ] = [ g ] ∗ ◦ [ f ] where [ g ] ∗ = µ Z ◦ M [ g ]. It follo ws that when v : X Y and w : Y Z , then [ g ◦ v ] = [ g ] ◦ v 0 , [ w ◦ f ] = M w 0 ◦ [ f ] a nd [ w ◦ v ] = η Z ◦ w 0 ◦ v 0 . It should be noted that it doe s not make se ns e to say that a mor phism in C 0 is pure or not. Indeed, ea ch morphism ϕ : X → M Y in C 0 gives rise in K M bo th to a pur e morphism v = J ( ϕ ) : X → M Y and to a mor phism f =] ϕ [: X → Y , related by [ v ] = η M Y ◦ [ f ] in C 0 . C 0 X [ f ] / / M Y X [ v ] / / v 0 ( ( Q Q Q Q Q Q Q Q Q Q M Y = Y η Y O O = M 2 Y X ϕ / / [ J ( ϕ )] 6 6 m m m m m m m m M Y η M Y O O K M X f / / Y X v = J ( v 0 ) / / /o /o /o /o Y M Y X ] ϕ [ / / J ( ϕ ) 6 6 6v 6v 6v 6v 6v Y In addition, the functor J : C 0 → K M has a right adjoint, which means that for each ob ject X there is a n ob ject X † called the lifting of X , with a n isomo rphism K M ( X, Y ) ∼ = C 0 ( X, Y † ) na tural in X a nd Y . Le t us assume that the mono r e quir ement is satisfied by the mona d, which means that η X is a mono for every ob ject X , or equiv alen tly tha t the functor J is faithful, so that it defines an isomo r phism from C 0 to C M . 2.2 Effects In this section we define the effect of a mo rphism f as a kind of measure of ho w fa r f is fro m b eing pur e: pure morphisms are effect-fr ee and the effect o f v ◦ f , when v is pure, is the same as the effect of f . Definition 2.2. Let K be a ca tegory with a wide subcatego ry C and with a pure terminal ob ject 1 . The effe ct o f a morphism f : X → Y is the morphism E ( f ) = h i Y ◦ f : X → 1. W e denote f ≈ f ′ when f : X → Y and f ′ : X → Y ′ hav e the same effect: ∀ f : X → Y , ∀ f ′ : X → Y ′ , f ≈ f ′ ⇐ ⇒ h i Y ◦ f = h i Y ′ ◦ f ′ . A morphism f : X → Y is effe ct-fr e e if E ( f ) = E (id X ), which means that E ( f ) = h i X . The fo llowing prop er ties ar e easily derived fro m the definition. Prop ositi o n 1 . The same-effe ct r elatio n ≈ is an e quivalenc e re lation b etwe en morph isms with the same domain that satisfies: • Pur e morphisms ar e effe ct-fr e e. ∀ v : X Y , v ≈ id X . • Substitut ion. ∀ f : X → Y , ∀ g : Y → Z , ∀ g ′ : Y → Z ′ , g ≈ g ′ = ⇒ g ◦ f ≈ g ′ ◦ f . • Pur e wiping. ∀ f : X → Y , ∀ w : Y Z , w ◦ f ≈ f . R emark 2 . E ff ects in a Kleisli category . Within the s ame fra mework as in remark 1, let us a ssume that there is a terminal ob ject 1 in C 0 , or equiv a lently in C M . F or each ob ject X , the pur e morphism h i X : X 1 stands for [ h i X ] = η 1 ◦ h i X : X → M 1 in C 0 , and for each morphism f : X → Y in K M the effect E ( f ) o f f stands for [ h i Y ◦ f ] = M h i Y ◦ [ f ] : X → M 1 in C 0 . Let ≈ 0 denote the relation b etw een morphisms in C 0 defined by [ f ] ≈ 0 [ f ′ ] if and only if f ≈ f ′ . Then in C 0 : ∀ ϕ : X → M Y , ∀ ϕ ′ : X → M Y ′ , ϕ ≈ 0 ϕ ′ ⇐ ⇒ M h i Y ◦ ϕ = M h i Y ′ ◦ ϕ ′ . 4 2.3 Consistency Now we define a cons is tency relation b etw een tw o pa rallel morphisms . Definition 2.3. Let K b e a catego ry w ith a wide subca tegory C . A c onsistency relation ⊳ is a relation betw een par a llel mor phisms, the second one b eing pure, which satisfies : • Pur e r eflexivity . ∀ v : X Y , v ⊳ v . • Comp atibility with c omp osition . ∀ f : X → Y , ∀ g : Y → Z , ∀ u : Y Y ′ , ∀ v : X Y ′ , ∀ w : Y ′ Z , ( u ◦ f ⊳ v ) ∧ ( g ⊳ w ◦ u ) = ⇒ g ◦ f ⊳ w ◦ v . X f - - v ⊳ / / /o /o /o /o Y ′ w ⊳ / / /o /o /o /o Z Y g > > u O O O = ⇒ X g ◦ f 4 4 w ◦ v ⊳ / / /o /o /o /o /o /o /o /o /o /o Z Two par allel morphisms f and f ′ are called c onsistent when f ⊳ v ⊲ f ′ for some pure mo r phism v , this is denoted f ⊳ ⊲ f ′ . The fo llowing prop er ties ar e easily derived fro m the definition. Prop ositi o n 2. L et K b e a c ate gory with a wide sub c ate gory C and with a c onsistency r elation ⊳ . Then: • Pr eservation by c omp osition. ∀ f : X → Y , ∀ v : X Y , ∀ g : Y → Z , ∀ w : Y Z , ( f ⊳ v ) ∧ ( g ⊳ w ) = ⇒ g ◦ f ⊳ w ◦ v . X f ; ; v ⊳ / / /o /o /o /o Y g ; ; w ⊳ / / /o /o /o /o Z = ⇒ X g ◦ f 4 4 w ◦ v ⊳ / / /o /o /o /o /o /o /o /o /o /o Z • Pur e substitu tion. ∀ v : X Y , ∀ g : Y → Z , ∀ w : Y Z , g ⊳ w = ⇒ g ◦ v ⊳ w ◦ v . • Pur e r eplac ement . ∀ f : X → Y , ∀ v : X Y , ∀ w : Y Z , f ⊳ v = ⇒ w ◦ f ⊳ w ◦ v . Definition 2.4. An effe ct c ate gory ( C j K , ⊳ ) is made o f a c ategory K and a wide subcatego ry C of K , with a pure terminal ob ject 1 and the same-effect relation ≈ as in definition 2.2, tog ether with a consistency relation ⊳ which satisfie s : • Complementarity with ≈ . ∀ f , f ′ : X → Y , ( f ≈ f ′ ) ∧ ( f ⊳ ⊲ f ′ ) = ⇒ f = f ′ . In essence, the co mplemen tarity prop erty can b e stated as follows: if t wo morphisms have the same e ffect and are consistent, then they are equal. The fo llowing prop er ties ar e easily derived. Prop ositi o n 3. L et ( C j K, ⊳ ) b e an effe ct c ate gory. Then: • Consistency on effe cts. ∀ f : X → Y , ( ∃ v , f ⊳ v ) = ⇒ E ( f ) ⊳ h i X . • Consistency on pur e morphisms. ∀ v, v ′ : X Y , v ⊳ v ′ ⇐ ⇒ v = v ′ . • Consistency is unambiguous. ∀ f : X → Y , ∀ v : X Y , f ⊳ ⊲ v ⇐ ⇒ f ⊳ v . R emark 3 . It follows that a pure morphism v is consistent with itself and with no other pur e morphism. In general a morphism f may be consistent with no pure mo rphism or with sev eral ones . The relatio n ⊳ ⊲ is symmetric but in gene r al it is not r eflexive. R emark 4 . Let K be a catego ry with a wide sub catego ry C and with a pure terminal ob ject 1 . Then the same-effect relation ≈ is uniquely defined, and ther e is a “trivial” consistency re la tion: the e quality of pure morphisms. But neither the existence nor the unicity of a non-trivial cons istency re lation ⊳ is gua ranteed. 5 2.4 Extended consistency The co nsistency ⊳ is a relatio n b etw een tw o mor phisms, the seco nd o ne b eing pure. It can b e extended to pairs of arbitra ry mo rphisms. Definition 2. 5. In an effect categ o ry ( C j K , ⊳ ), an extende d c onsistency is a relatio n ◭ between parallel morphisms such that: • Extension . ∀ f : X → Y , ∀ v : X Y , f ⊳ v = ⇒ f ◭ v . • Substitut ion . ∀ f : X → Y , ∀ g , g ′ : Y → Z , g ◭ g ′ = ⇒ g ◦ f ◭ g ′ ◦ f . The sy mmetric r elation ◭ ◮ is defined b y f ◭◮ f ′ if and only if there is a morphism f ′′ such that f ◭ f ′′ ◮ f ′ . This rela tio n ◭◮ is weak er than the re lation ⊳⊲ . It follows easily that ◭ is r eflexive and that f ◭ f ′ implies f ◭◮ f ′ . R emark 5 . It is easy to chec k tha t in an effect ca tegory ( C j K, ⊳ ) there is a smalles t ex tended consistency ◭ , which is defined a s follows: ∀ h, h ′ : X → Y , h ◭ h ′ ⇐ ⇒ ∃ f : X → Y , ∃ g : Y → Z , ∃ w : Y Z , ( h = g ◦ f ) ∧ ( h ′ = w ◦ f ) ∧ ( g ⊳ w ) X f / / Y g ; ; w ⊳ / / /o /o /o /o Z ⇐ ⇒ X g ◦ f 4 4 w ◦ f ◭ / / /o /o /o /o /o /o /o /o /o /o Z In addition, this re lation ◭ satisfies pure r eplacement: ∀ f , f ′ : X → Y , ∀ w : Y Z , f ◭ f ′ = ⇒ w ◦ f ◭ w ◦ f ′ . 2.5 Examples of effect categories Several examples are introduced in this sectio n. F or each example, the s ame-effect relatio n ≈ is descr ib ed, then a consistency relation ⊳ is chosen in such a w a y tha t we get an e ffect category , and the smalle s t extended consistency rela tion ◭ is de s crib ed. It will b e check ed in sections 3.8 a nd 4.4 that in each ex ample the c hosen consistency relation gives rise to a Ca rtesian effect categor y . The examples ab out err ors, lists, finite multisets and finite sets are provided directly by a mo nad M , then K M and C M are defined as in rema rk 1. States could be treated with mo nads, at the cost of using an ex tra adjunction, but this would no t b e p os sible for partiality over an arbitrar y base categ o ry . Err ors . Let C 0 be a catego ry with an initial ob ject 0 and w ith a distinguished ob ject E (for “erro rs”), hence with a unique morphism ! E : 0 → E . Let us assume that there are copro ducts of the form X + E that b ehave wel l in the sense of extensivity (Carb o ni et al., 1 993): for every ϕ : X → Y + E , there is a copro duct X = D ϕ + D ϕ with tw o mo rphisms ϕ Y : D ϕ → Y and ϕ E : D ϕ → E such that ϕ = ϕ Y + ϕ E . The err or monad on C 0 has M X = X + E a s endofunctor a nd the copro jection η X : X → X + E as unit. A morphism f : X → Y in the Kleisli ca tegory K M stands fo r a morphism [ f ] : X → Y + E in C 0 , such that [ f ] = [ f ] Y + [ f ] E as e xplained above. A pur e morphism v = J ( v 0 ) : X Y in K M stands for [ v ] = η Y ◦ v 0 : X → Y + E in C 0 , suc h tha t [ v ] = v 0 +! E : X → Y + E in C 0 . Let us a ssume that C 0 has a terminal ob ject 1. F or each morphism f : X → Y in K M , the effect E ( f ) = h i Y ◦ f : X → 1 is suc h that [ E ( f )] = ( h i Y + id E ) ◦ [ f ] = h i D [ f ] + [ f ] E . All this can b e illustr a ted a s fo llows in C 0 , first for a pure 6 morphism v then for a morphism f and finally for the effect E ( f ); the vertical arr ows ar e the copro jections: X v 0 / / id X   Y   X [ v ] / / = = Y + E 0 ! E / / ! X O O E O O D [ f ] [ f ] Y / /   Y   X [ f ] / / = = Y + E D [ f ] [ f ] E / / O O E O O D [ f ] [ f ] Y / /   h i D [ f ] = ' ' Y h i Y / / 1   X [ E ( f )] / / = = 1 + E D [ f ] [ f ] E / / O O [ f ] E = 7 7 E id E / / E O O Let i [ f ] : D [ f ] → X deno te the copro jection and let ≃ → deno te an isomor phism in C 0 . • ∀ f : X → Y , ∀ f ′ : X → Y ′ , f ≈ f ′ ⇐ ⇒ ∃ i : D [ f ] ≃ → D [ f ′ ] , [ f ] E = [ f ′ ] E ◦ i . • ∀ f : X → Y , ∀ v = J ( v 0 ) : X Y , f ⊳ v ⇐ ⇒ [ f ] Y = v 0 ◦ i [ f ] . When C 0 is the category of s ets, we say that D ϕ is the domai n of definition of ϕ a nd that ϕ r aises t he err or e at x whenever ϕ ( x ) = e ∈ E , so that a morphism v is pure if and only if [ v ] do es no t rais e any er ror. Then, f ≈ f ′ means that [ f ] and [ f ′ ] rais e the same errors for the same ar guments, he nc e they hav e the s ame domain o f definition. F urthermor e , f ⊳ v mea ns that [ f ] co incides with [ v ] on D [ f ] , hence f ⊳ ⊲ f ′ means that [ f ] a nd [ f ′ ] coincide on D [ f ] ∩ D [ f ′ ] . Then the smalles t extended consis tency relation is suc h that for all f , f ′ : X → Y , f ◭ f ′ if and only if D [ f ] ⊆ D [ f ′ ] and [ f ] co incides with [ f ′ ] o n D [ f ] and also on D [ f ′ ] . It follows that ◭ is tr a nsitive and that ◭◮ is the same relation as ⊳ ⊲ . Partiality . A c ate gory of p artial morphisms is defined here, as in (Curien and Obtulowitz, 19 89), a s a categor y K with a wide sub ca tegory C suc h that the c a tegory K is enriched with a par tial o rder ≤ and ev ery pure arrow is maximal fo r ≤ . The n the mo r phisms in K are called the p artial functions and the morphisms in C the total functions , as in the fundamen tal situatio n of sets. In addition, let us assume that ther e is a pure terminal ob ject 1, and wher efore the effect of a morphism f : X → Y is the mor phism h i Y ◦ f (in (Curien and Obtulowitz, 1 9 89) this morphism is ca lled the domain of definition of f ). • ∀ f : X → Y , ∀ f ′ : X → Y ′ , f ≈ f ′ ⇐ ⇒ h i Y ◦ f = h i Y ◦ f ′ . • ∀ f : X → Y , ∀ v = J ( v 0 ) : X Y , f ⊳ v ⇐ ⇒ f ≤ v . • ∀ f , f ′ : X → Y , f ◭ f ′ ⇐ ⇒ f ≤ f ′ . W e add, as a new axiom, the co mplemen tarity of ≈ and ⊳ . On sets, with the usual no tion of partial function, the inclusion of C in K has a right a djoint with lifting X † = X + 1, so that the partial functions fr om X to Y c a n be identified to the (total) functions from X to Y + 1 and the partial o rder ≤ corr esp onds to the inclusion of the domains of definition (in their usual sense, as subsets). Then b oth p o ints o f view (partiality a nd er ror) are equiv alen t. State . Let C 0 be a category with a distinguished o b ject S (for “states” ) and with pro ducts of the form S × X . F or eac h set X let σ X : S × X → S and π X : S × X → X denote the pro jections. Le t K be the category with the the sa me ob jects a s C 0 and with a mo rphism f : X → Y for each [ f ] : S × X → S × Y in C 0 ; we say that f in K stands for [ f ] in C 0 . Let C b e the wide s ubca tegory o f K w ith the pur e morphisms v = J ( v 0 ) : X Y standing for [ v ] = id S × v 0 : S × X → S × Y . Let us assume that C 0 has a terminal ob ject 1. W e ma y identify S × 1 with S , so that the morphism h i X : X 1 stands for the pro jection σ X : S × X → S and the effect of a morphism f : X → Y stands for σ Y ◦ [ f ] : S × X → S . • ∀ f : X → Y , ∀ f ′ : X → Y ′ , f ≈ f ′ ⇐ ⇒ σ Y ◦ [ f ] = σ Y ′ ◦ [ f ′ ]. 7 • ∀ f : X → Y , ∀ v = J ( v 0 ) : X Y , f ⊳ v ⇐ ⇒ π Y ◦ [ f ] = v 0 ◦ π X . • ∀ f , f ′ : X → Y , f ◭ f ′ ⇐ ⇒ π Y ◦ [ f ] = π Y ◦ [ f ′ ]. It follows that ◭ is an equiv alence relation, so that ◭◮ is the same as ◭ . On sets, f ≈ f ′ means that [ f ] a nd [ f ′ ] mo dify the s tate in the same w ay , and f ⊳ v means that [ f ] alwa ys returns the same v a lue as v 0 , so that f ⊳ ⊲ f ′ means that [ f ] and [ f ′ ] b oth always r eturn the same v alue, which in a ddition do es not dep end on the state, while f ◭ f ′ (as well as f ◭ ◮ f ′ ) means that [ f ] and [ f ′ ] b oth always r eturn the same v alue, which may dep end o n the state. Lists . Let us consider the list monad with endofunctor L on the categ ory of sets. The unit η maps each x to ( x ) and the multiplication µ flattens each list of lists. Since 1 is a sing leton, a lis t ℓ in L (1) may be identified to its leng th len(() ℓ ) in N , a nd the effect o f a morphism f : X → Y to len( ◦ ) f : X → N . Then, a mo r phism f is effect-free when len( ◦ ) f is the consta nt function 1. F or each x ∈ X a nd k ∈ N , w e denote by ( x ) k the list ( x, . . . , x ) where x is r e pea ted k times. Mo re generally , fo r each list x = ( x 1 , . . . , x n ) ∈ L ( X ) a nd each list of naturals k = ( k 1 , . . . , k n ) with the same length as x , we deno te by x k the list ( x 1 , . . . , x 1 , . . . , x n , . . . , x n ) where each x i is rep eated k i times. • ∀ f : X → Y , ∀ f ′ : X → Y ′ , f ≈ f ′ ⇐ ⇒ ∀ x ∈ X , len(() f ( x )) = len(() f ′ ( x )). • ∀ f : X → Y , ∀ v = J ( v 0 ) : X Y , f ⊳ v ⇐ ⇒ ∀ x ∈ X , ∃ k ∈ N , [ f ]( x ) = ( v 0 ( x )) k . • ∀ f , f ′ : X → Y , f ◭ f ′ ⇐ ⇒ ∀ x ∈ X , ∃ k ∈ L ( N ) , [ f ]( x ) = [ f ′ ]( x ) k . It follows that f ⊳ ⊲ f ′ if and only if for ea ch x ∈ X there is so me y ∈ Y that is the unique element (if a ny) in the lists [ f ]( x ) and [ f ′ ]( x ), and that f ◭◮ f ′ as so on as f and f ′ are parallel. Finite (multi)sets . The example of lists can easily b e adapted to the finite multiset monad and to the fi nite set monad on the categor y o f sets. F o r the finite m ultiset monad, M fin (1) can b e iden tified to N a nd the effect of a mor phism to the cardinal of its ima ge. • ∀ f : X → Y , ∀ f ′ : X → Y ′ , f ≈ f ′ ⇐ ⇒ ∀ x ∈ X , ca rd(() f ( x )) = card(() f ′ ( x )). • ∀ f : X → Y , ∀ v = J ( v 0 ) : X Y , f ⊳ v ⇐ ⇒ ∀ x ∈ X , [ f ]( x ) ⊆ { v 0 ( x ) } . • ∀ f , f ′ : X → Y , f ◭ f ′ ⇐ ⇒ ∀ x ∈ X , [ f ]( x ) ⊆ [ f ′ ]( x ) . F or the finite set monad, the definitions o f ⊳ and ◭ are similar, but ≈ is different. Since P fin (1) has only t wo elements ∅ and 1 , w e get f ≈ f ′ if a nd only if for all x ∈ X either bo th f ( x ) and f ′ ( x ) ar e empty or bo th are non- e mpt y . 2.6 Results in ev aluation logic In (Moggi, 19 9 5), within the framework of evaluatio n lo gic and with respect to a stro ng monad satisfying some extra prop erties, Mo g gi defines the r elation c ⇓ a , whic h means that the v alue a is a r esu lt of the computation c . With the sa me notations as in r emark 1, c : 1 → M X and a : 1 → X are morphisms in C 0 , o r equiv alently c = [ f ] for a morphism f : 1 → X in K M and a = v 0 : X → Y yields a pur e morphism v = J ( v 0 ) : 1 X . Then it may happ en that f is c onsisten t with v in the s ense of this pap er. The following table compar es b oth notions for several mona ds on sets. Monad Results (Moggi, 199 5) Consistency (this pap er ) M Y c ⇓ a f ⊳ v Y + E c = a (thus, c is to tal) c ∈ Y = ⇒ c = a ( Y × S ) S ∃ s ∈ S , ∃ s ′ ∈ S , c ( s ) = ( a, s ′ ) ∀ s ∈ S , ∃ s ′ ∈ S , c ( s ) = ( a, s ′ ) L ( Y ) a ∈ c ∃ k ∈ N , c = ( a ) k P fin ( Y ) a ∈ c c = { a } or c = ∅ 8 F rom this table we see that in genera l f ⊳ v 6⇒ c ⇓ a and c ⇓ a 6⇒ f ⊳ v . It ca n easily be seen from the example of the state monad that having the same results is not a consistency relation in genera l, since t wo different morphisms may hav e the same effect and the s ame results. T he r efore, the no tio n of result in ev aluation lo g ic do es not eas ily fit with our notion o f cons istency . 3 Cartesian effect categories 3.1 Cartesian categories In this pap er a Cartesia n c ate gory is a catego ry with chosen finite pro ducts. W e deno te b y 1 the terminal ob ject, × for the pro ducts and p, q , r, s, t, . . . (with indices) for the pr o jections. The binary pro duct defines a functor × : C 2 → C such that for all v 1 : X 1 → Y 1 and v 2 : X 2 → Y 2 , the mor phism v 1 × v 2 : X 1 × X 2 → Y 1 × Y 2 is the unique mor phism tha t satisfies the binary pr o duct pr op erty : q 1 ◦ ( v 1 × v 2 ) = v 1 ◦ p 1 q 2 ◦ ( v 1 × v 2 ) = v 2 ◦ p 2 X 1 v 1 / / = Y 1 X 1 × X 2 v 1 × v 2 / / p 1 O O p 2   Y 1 × Y 2 q 1 O O q 2   X 2 v 2 / / Y 2 = In a Cartes ia n category C , the swap natural transformation c , with compo nents c X 1 ,X 2 : X 1 × X 2 → X 2 × X 1 , is defined fr o m the pro jections p i : X 1 × X 2 → X i and p ′ i : X 2 × X 1 → X i by p ′ i ◦ c X 1 ,X 2 = p i for i = 1 , 2. It fo llows that c X 2 ,X 1 = c − 1 X 1 ,X 2 . Now, Cartesian pro ducts in a category are generalized, first as s emi-pure pro ducts, then as s equential pro ducts, in an effect categor y . 3.2 Semi-pure pro ducts Let us consider an effect category ( C j K, ⊳ ) where C is a Cartesia n category . W e define the semi-pur e pr o ducts as tw o gra ph homomorphisms ⋉ : C × K → K and ⋊ : K × C → K that e x tend × and that satisfy some generalizatio n of the bina ry pro duct prop erty inv olving the co nsistency relation ⊳ . while the univ ersal prop erty o f a binary pro duct consists in t wo equalities , the universal pr op erty o f a semi-pure pro duct consists in one equality a nd one consistency . Definition 3.1 . Let ( C j K, ⊳ ) b e an effect categor y with a binar y pr o duct × o n C . A graph ho momor- phism ⋉ : C × K → K is the left semi-pur e pr o duct o n ( C j K, ⊳ , × ) if it extends × a nd satisfies the left semi-pur e pr o duct pr op erty : for all v 1 : X 1 Y 1 and f 2 : X 2 → Y 2 , the morphism v 1 ⋉ f 2 : X 1 × X 2 → Y 1 × Y 2 is the unique mor phism s uch that: q 1 ◦ ( v 1 ⋉ f 2 ) ⊳ v 1 ◦ p 1 q 2 ◦ ( v 1 ⋉ f 2 ) = f 2 ◦ p 2 X 1 v 1 / / /o /o /o /o /o /o /o /o ⊳ Y 1 X 1 × X 2 v 1 ⋉ f 2 / / p 1 O O O O p 2   O O Y 1 × Y 2 q 1 O O O O q 2   O O X 2 f 2 / / Y 2 = Symmetrically , a graph ho momorphism ⋊ : K × C → K is the r ight semi-pur e pr o duct on ( C j K , ⊳ , × ) if it extends × and satisfies the right semi-pu re pr o duct pr op erty : for all f 1 : X 1 → Y 1 and v 2 : X 2 Y 2 , the 9 morphism f 1 ⋊ v 2 : X 1 × X 2 → Y 1 × Y 2 is the unique mor phism s uch that: q 1 ◦ ( f 1 ⋊ v 2 ) = f 1 ◦ p 1 q 2 ◦ ( f 1 ⋊ v 2 ) ⊳ v 2 ◦ p 2 X 1 = f 1 / / Y 1 X 1 × X 2 f 1 ⋊ v 2 / / p 2   O O p 1 O O O O Y 1 × Y 2 q 1 O O O O q 2   O O X 2 v 2 / / /o /o /o /o /o /o /o /o Y 2 ⊳ A Ca rtesian effe ct c ate gory is an effect c a tegory ( C j K , ⊳ ) with a binary pro duct × on C and with semi-pure pro ducts ⋉ and ⋊ (for short, it may be denoted C j K o r simply K ). A s traightforw ard co ns equence o f definition 3 .1 is that the right semi-pure pro duct can be determined from the left o ne, as follows. Consequen tly , fro m now on, we gener ally o mit the right se mi- pure pro ducts. Prop ositi o n 4. In a Cartesian effe ct c ate gory. for al l f 1 : X 1 → Y 1 and v 2 : X 2 Y 2 : ( f 1 ⋊ v 2 ) = c Y 2 ,Y 1 ◦ ( v 2 ⋉ f 1 ) ◦ c X 1 ,X 2 . In a binary pr o duct v 1 × v 2 , obviously the firs t pro jection q 1 ◦ ( v 1 × v 2 ) does no t dep end on v 2 , and symmetrically the s e cond pro jection q 2 ◦ ( v 1 × v 2 ) does not depend on v 1 . F or a left semi-pure pr o duct v 1 ⋉ f 2 , this r e mains true for the second pro jection but no t fo r the first one. How e ver, a conseq uence of the complementarit y o f ⊳ with ≈ is that q 1 ◦ ( v 1 ⋉ f 2 ) depends o n f 2 precisely through its effect E ( f 2 ), as stated in the next pr op osition. Prop ositi o n 5. In a C artesian effe ct c ate gory, for al l v 1 : X 1 Y 1 , f 2 : X 2 → Y 2 and f ′ 2 : X 2 → Y 2 , E ( q 1 ◦ ( v 1 ⋉ f 2 )) = E ( v 1 ⋉ f 2 ) = E ( f 2 ◦ p 2 ) and: E ( f 2 ) = E ( f ′ 2 ) = ⇒ q 1 ◦ ( v 1 ⋉ f 2 ) = q 1 ◦ ( v 1 ⋉ f ′ 2 ) . Pr o of. The first result derives from the pur e w iping pr op erty of the effect. F or the sec o nd r esult, let h = v 1 ⋉ f 2 and h ′ = v 1 ⋉ f ′ 2 . The left semi-pure pro duct pr op erty implies that q 1 ◦ h ⊳ ⊲ q 1 ◦ h ′ and q 2 ◦ h = q 2 ◦ h ′ . The latter implies that q 2 ◦ h ≈ q 2 ◦ h ′ , and thus by pure wiping w e hav e also q 1 ◦ h ≈ q 1 ◦ h ′ . The r e sult now follows from the complementarit y of ⊳ with ≈ . The next propos ition fo llows from the fact that the restrictio n o f ⋉ to C 2 coincides with the binary pro duct functor × on C . Prop ositi o n 6. In a Cartesian effe ct c ate gory, for al l obje cts X 1 and X 2 : id X 1 ⋉ id X 2 = id X 1 × id X 2 = id X 1 × X 2 . R emark 6 . Let us as sume that the following unicity c ondition holds: ∀ h, h ′ : X → Y 1 × Y 2 , ( q 1 ◦ h ⊳ ⊲ q 1 ◦ h ′ ) ∧ ( q 2 ◦ h = q 2 ◦ h ′ ) = ⇒ h = h ′ . In this case, if there is a graph ho momorphism ⋉ : C × K → K extending × a nd satisfying the left semi-pure pro duct pro p er ty , then ⋉ is the left semi-pure pro duct. 3.3 Sequen tial products In accorda nce with the intended meaning of “ sequential”, we define sequen tial pr o ducts as comp osed from t wo consecutive semi-pure pr o ducts. 10 Definition 3.2. In a Cartesian effect category , the pa ir of se quen tial pr o ducts comp osed from the semi- pro ducts ⋉ , ⋊ is made of the graph homomorphisms ⋉ seq , ⋊ seq : K 2 → K (the left and right seq ue ntial pro ducts, resp ectively) defined as follows: • for all f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 : f 1 ⋉ seq f 2 = (id Y 1 ⋉ f 2 ) ◦ ( f 1 ⋊ id X 2 ) • for all f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 : f 1 ⋊ seq f 2 = ( f 1 ⋊ id Y 2 ) ◦ (id X 1 ⋉ f 2 ) X 1 = f 1 / / Y 1 id / / /o /o /o /o /o /o /o ⊳ Y 1 X 1 × X 2 f 1 ⋊ id / / p 2   O O O p 1 O O O O O Y 1 × X 2 r 1 O O O O O r 2   O O O id ⋉ f 2 / / Y 1 × Y 2 q 1 O O O O O q 2   O O O X 2 id / / /o /o /o /o /o /o /o X 2 ⊳ f 2 / / Y 2 = X 1 id / / /o /o /o /o /o /o /o ⊳ X 1 = f 1 / / Y 1 X 1 × X 2 id ⋉ f 2 / / p 1 O O O O O p 2   O O O X 1 × Y 2 s 1 O O O O O s 2   O O O f 1 ⋊ id / / Y 1 × Y 2 q 1 O O O O O q 2   O O O X 2 f 2 / / Y 2 = id / / /o /o /o /o /o /o /o Y 2 ⊳ It follows easily fro m prop o sition 4 that the right s equential pro duct can be determined from the left one, as follows. Consequen tly , from now on, we g enerally omit the right seq uent ial pro ducts. Prop ositi o n 7. In a Cartesian effe ct c ate gory, for al l f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 : ( f 1 ⋊ seq f 2 ) = c Y 2 ,Y 1 ◦ ( f 2 ⋉ seq f 1 ) ◦ c X 1 ,X 2 . Prop ositi o n 8. In a Cartesian effe ct c ate gory, the left se quential pr o duct ⋉ seq extends the left semi-pur e pr o duct ⋉ . Pr o of. Let v : X 1 Y 1 and f : X 2 → Y 2 . Since v ⋉ seq f = (id Y 1 ⋉ f ) ◦ ( v ⋊ id X 2 ) and since ⋊ e xtends the binary pro duct × on C 2 : v ⋉ seq f = (id Y 1 ⋉ f ) ◦ ( v × id X 2 ) . The left semi-pur e pr o duct pr op erty yields: q 1 ◦ (id Y 1 ⋉ f ) ⊳ r 1 and q 2 ◦ (id Y 1 ⋉ f ) = f ◦ r 2 so that by pure substitution: q 1 ◦ ( v ⋉ seq f ) ⊳ r 1 ◦ ( v × id X 2 ) and q 2 ◦ ( v ⋉ seq f ) = f ◦ r 2 ◦ ( v × id X 2 ) hence from the binar y pro duct prop erty we g et: q 1 ◦ ( v ⋉ seq f ) ⊳ v ◦ p 1 and q 2 ◦ ( v ⋉ seq f ) = f ◦ p 2 which is the left se mi-pure pro duct pro p erty . R emark 7 . It follows from prop osition 8 that we may drop the s ubs cript “seq”. Definition 3.3. In a Cartesian effect category , for all f 1 : X → Y 1 and f 2 : X → Y 2 the left p airing of f 1 and f 2 is h f 1 , f 2 i l = ( f 1 ⋉ f 2 ) ◦ h id X , id X i : X → Y 1 × Y 2 and the righ t p airing of f 1 and f 2 is h f 1 , f 2 i r = ( f 1 ⋊ f 2 ) ◦ h id X , id X i : X → Y 1 × Y 2 . R emark 8 . Another point of view on sequen tial pr o ducts, as “direct” generaliza tions of binar y pro ducts (independently fro m a ny a priori semi-pure pr o ducts) is given in sectio n 3.7. 11 3.4 Pure morphisms are cen tral The next definition is similar to the definition o f central morphisms in a binoidal categ ory , see section 4.1. Definition 3.4. In a Cartesian effect catego ry , a morphism k 1 is c entr al if fo r each morphism f 2 : k 1 ⋉ f 2 = k 1 ⋊ f 2 . Then it follows fro m pro p osition 7 that f 2 ⋉ k 1 = f 2 ⋊ k 1 . The c enter C K of K is made of the ob jects of K together with the c e ntral mor phisms, we will prove in theorem 12 that C K is a sub categ o ry o f K . R emark 9 . According to definitio n 3 .2, in a Cartesia n effect ca teg ory a mor phism k 1 : X 1 → Y 1 is central if and only if for each morphism f 2 : X 2 → Y 2 : ( k 1 ⋊ id Y 2 ) ◦ (id X 1 ⋉ f 2 ) = (id Y 1 ⋉ f 2 ) ◦ ( k 1 ⋊ id X 2 ) . R emark 10 . It follows from definition 3.2 a nd prop osition 6 that the ident ities are central. Theorem 9 now prov es that this is v alid for all pure morphisms. Theorem 9 . In a Cartesian effe ct c ate gory, every pur e morphism is c entr al. Pr o of. Giv en v : X 1 Y 1 and f : X 2 → Y 2 , let us prov e tha t the left semi-pure pro duct v ⋉ f is equa l to the right sequential pro duct v ⋊ f . Let: h = v ⋊ f = ( v ⋊ id Y 2 ) ◦ (id X 1 ⋉ f ) = ( v × id Y 2 ) ◦ (id X 1 ⋉ f ) . Using the binary pro duct prop erty: q 1 ◦ h = v ◦ s 1 ◦ (id X 1 ⋉ f ) and q 2 ◦ h = s 2 ◦ (id X 1 ⋉ f ) then the left semi-pur e pro duct prop er ty: s 1 ◦ (id X 1 ⋉ f ) ⊳ p 1 and s 2 ◦ (id X 1 ⋉ f ) = f ◦ p 2 we get by pure r e pla cement: q 1 ◦ h ⊳ v ◦ p 1 and q 2 ◦ h = f ◦ p 2 which means that the left semi-pure pro duct pro p e rty is satisfied: h = v ⋉ f , as requir ed. R emark 11 . In view of theorem 9 ther e would b e no ambiguit y in denoting × for the semi-pure pr o ducts ⋉ and ⋊ , howev er we will not us e this o pp ortunity , in order to keep in mind tha t the semi-pure pr o ducts are not real pro ducts. 3.5 F un ctoriality properties As reminded in section 3.1, the binary pro duct in a Cartesian categor y is a functor. In this section it is prov ed that similar ly the semi-pure pro ducts in a Cartesia n effect ca tegory are functors. Lemma 10. In a Cartesian effe ct c ate gory, for all X 1 , f 2 : X 2 → Y 2 and g 2 : Y 2 → Z 2 : (id X 1 ⋉ g 2 ) ◦ (id X 1 ⋉ f 2 ) = id X 1 ⋉ ( g 2 ◦ f 2 ) . Pr o of. The pro of is easily obta ined by chasing the following diagr a m a nd using the compatibility o f consis- tency with comp os ition. X 1 id / / /o /o /o /o /o /o ⊳ X 1 id / / /o /o /o /o /o /o ⊳ X 1 X 1 × X 2 p 1 O O O O p 2   O O id ⋉ f 2 / / X 1 × Y 2 s 1 O O O O s 2   O O id ⋉ g 2 / / X 1 × Z 2 s ′ 1 O O O O s ′ 2   O O X 2 f 2 / / Y 2 = g 2 / / Z 2 = 12 Lemma 11. In a C artesian effe ct c ate gory, for al l f 1 : X 1 → Y 1 , k 1 : Y 1 → Z 1 , f 2 : X 2 → Y 2 and g 2 : Y 2 → Z 2 with k 1 c entra l: ( k 1 ⋉ g 2 ) ◦ ( f 1 ⋉ f 2 ) = ( k 1 ◦ f 1 ) ⋉ ( g 2 ◦ f 2 ) Pr o of. According to definition 3.2: ( k 1 ⋉ g 2 ) ◦ ( f 1 ⋉ f 2 ) = (id Z 1 ⋉ g 2 ) ◦ ( k 1 ⋊ id Y 2 ) ◦ (id Y 1 ⋉ f 2 ) ◦ ( f 1 ⋊ id X 2 ) . Since k 1 is central, this is equa l to (id Z 1 ⋉ g 2 ) ◦ (id Z 1 ⋉ f 2 ) ◦ ( k 1 ⋊ id X 2 ) ◦ ( f 1 ⋊ id X 2 ). The result now follows from lemma 10 and definition 3.2 aga in. Theorem 12. In a Cartesian effe ct c ate gory C j K , the c enter C K is a wide sub c ate gory of K that c ontains C , and the r estrictions of the se quential pr o ducts ar e functors ⋉ : C K × K → K and ⋊ : K × C K → K . Pr o of. The central mor phisms form a sub categor y of K : this comes from remar k 10 for identities and from lemma 11 and its symmetric version for comp os ition. The center C K is wide by definition, and it contains C b ecaus e of theorem 9. The res tr ictions of the left sequential pr o duct is a functor : by pr op osition 6 for ident ities and lemma 1 1 for co mpo sition. Symmetrically , the restr ictions of the right s equential pro duct is a functor. 3.6 Naturalit y prop erties As reminded in section 3.1, a Cartes ian ca tegory C with × : C 2 → C and 1 forms a symmetric monoidal category , which means that the pro jections ca n b e com bined in order to get natura l isomor phisms a, r, l , c with comp onents: • a X = a X 1 ,X 2 ,X 3 : ( X 1 × X 2 ) × X 3 → X 1 × ( X 2 × X 3 ), • r X : 1 × X → X , l X : X × 1 → X , • c X = c X 1 ,X 2 : X 1 × X 2 → X 2 × X 1 , which s atisfy the symmetric mo no idal coherence conditions (Mac La ne, 19 97). In this s ection we prov e that in a Cartesian effect ca tegory C j K , the natural isomorphis ms a, r, l, c that are defined from C satisfy more general natura lity co nditions, inv olving the sequen tial pr o ducts ⋉ , ⋊ . The verification o f the next r esult is straightforward fr om the definitions. Lemma 13. In a Cartesian effe ct c ate gory, for all f 1 , f 2 , f 3 and pur e v 1 , v 2 , v 3 :        a Y ◦ ( f 1 ⋊ ( v 2 ⋊ v 3 )) = (( f 1 ⋊ v 2 ) ⋊ v 3 ) ◦ a X a Y ◦ ( v 1 ⋉ ( f 2 ⋊ v 3 )) = (( v 1 ⋉ f 2 ) ⋊ v 3 ) ◦ a X a Y ◦ ( v 1 ⋉ ( v 2 ⋉ f 3 )) = (( v 1 ⋉ v 2 ) ⋉ f 3 ) ◦ a X Theorem 14. In a C artesian effe ct c ate gory, for al l f : X → Y , f 1 : X 1 → Y 1 , f 2 : X 2 → Y 2 and f 3 : X 3 → Y 3 :                  r Y ◦ (id 1 ⋉ f ) = f ◦ r X l Y ◦ ( f ⋊ id 1 ) = f ◦ l X c Y ◦ ( f 1 ⋊ f 2 ) = ( f 2 ⋉ f 1 ) ◦ c X a Y ◦ ( f 1 ⋉ ( f 2 ⋉ f 3 )) = (( f 1 ⋉ f 2 ) ⋉ f 3 ) ◦ a X a Y ◦ ( f 1 ⋊ ( f 2 ⋊ f 3 )) = (( f 1 ⋊ f 2 ) ⋊ f 3 ) ◦ a X 13 Pr o of. Since r X and l X are the pro jections, the first tw o lines comes from the definition of semi-pur e pro ducts. Since c X is the swap morphism from se c tion 3.1, the third line is pro p osition 7. As for the fourth line, let us use the definition of sequential pro ducts: f 1 ⋉ ( f 2 ⋉ f 3 ) = (id ⋉ ( f 2 ⋉ f 3 )) ◦ ( f 1 ⋊ id) a nd f 2 ⋉ f 3 = (id ⋉ f 3 ) ◦ ( f 2 ⋊ id) hence by lemma 10: id ⋉ ( f 2 ⋉ f 3 ) = (id ⋉ (id ⋉ f 3 )) ◦ (id ⋉ ( f 2 ⋊ id)) and finally: f 1 ⋉ ( f 2 ⋉ f 3 ) = (id ⋉ (id ⋉ f 3 )) ◦ (id ⋉ ( f 2 ⋊ id)) ◦ ( f 1 ⋊ id) . In a symmetric wa y: ( f 1 ⋉ f 2 ) ⋉ f 3 = (id ⋉ f 3 ) ◦ ((id ⋉ f 2 ) ⋊ id) ◦ (( f 1 ⋊ id) ⋊ id) . Hence the res ult follows from the three lines of lemma 13, together with pro po sition 6 for dealing with ident ities. 3.7 The sequen t ial pro duct prop erties Sequential pro ducts also sa tisfy the left and ri ght se quential pr o duct pr op erties , a s defined b elow, whic h generalize the binary pr o duct prop erty . W e use an extended consistency ◭ , as defined in section 2.4. Definition 3.5. Let ( C j K, ⊳ ) be an effect ca tegory with an extended c o nsistency relation ◭ and with a pair of gr aph homomorphisms ⋉ ′ , ⋊ ′ : K 2 → K extending × . Then the left se quential pr o duct pr op erty states that for all f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 , the morphis m f 1 ⋉ ′ f 2 : X 1 × X 2 → Y 1 × Y 2 satisfies: q 1 ◦ ( f 1 ⋉ ′ f 2 ) ◭ f 1 ◦ p 1 q 2 ◦ ( f 1 ⋉ ′ f 2 ) = f 2 ◦ r 2 ◦ ( f 1 ⋊ ′ id X 2 ) X 1 f 1 / / ◭ Y 1 X 1 × X 2 f 1 ⋉ ′ f 2 / / p 1 O O O O O O f 1 ⋊ ′ id / / Y 1 × Y 2 q 1 O O O O O O q 2   O O O O O Y 1 × X 2 r 2   O X 2 f 2 / / Y 2 = Symmetrically , the right s e quential pr o duct pr op erty says that for a ll f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 , the morphism f 1 ⋊ ′ f 2 : X 1 × X 2 → Y 1 × Y 2 satisfies: q 1 ◦ ( f 1 ⋊ ′ f 2 ) = f 1 ◦ s 1 ◦ (id X 1 ⋉ ′ f 2 ) q 2 ◦ ( f 1 ⋊ ′ f 2 ) ◭ f 2 ◦ p 2 X 1 = f 1 / / Y 1 X 1 × Y 2 s 1 O O O X 1 × X 2 f 1 ⋊ ′ f 2 / / p 2   O O O O id ⋉ ′ f 2 / / Y 1 × Y 2 q 1 O O O O O O O q 2   O O O O X 2 f 2 / / Y 2 ◭ Prop ositi o n 15. In a Cartesia n effe ct c ate gory, the se quential pr o duct s ⋉ , ⋊ satisfy the se quential pr o duct pr op erties. 14 Pr o of. The left se q uent ial pro duct is defined a s f 1 ⋉ f 2 = (id Y 1 ⋉ f 2 ) ◦ ( f 1 ⋊ id X 2 ). Since ◭ extends ⊳ , the left semi-pure pro duct prop erty yields: q 1 ◦ (id Y 1 ⋉ f 2 ) ◭ r 1 and q 2 ◦ (id Y 1 ⋉ f 2 ) = f 2 ◦ r 2 so that by the subs titution prop erty o f ◭ : q 1 ◦ ( f 1 ⋉ f 2 ) ◭ r 1 ◦ ( f 1 ⋊ id X 2 ) a nd q 2 ◦ ( f 1 ⋉ f 2 ) = f 2 ◦ r 2 ◦ ( f 1 ⋊ id X 2 ) . The right semi- pur e pro duct prop erty implies that r 1 ◦ ( f 1 ⋊ id X 2 ) = f 1 ◦ p 1 , hence: q 1 ◦ ( f 1 ⋉ f 2 ) ◭ f 1 ◦ p 1 and q 2 ◦ ( f 1 ⋉ f 2 ) = f 2 ◦ r 2 ◦ ( f 1 ⋊ id X 2 ) which is the left se quential pro duct pr o p erty . R emark 12 . The following condition is calle d the extende d un icity condition: ∀ h, h ′ : X → Y 1 × Y 2 , ( q 1 ◦ h ◭◮ q 1 ◦ h ′ ) ∧ ( q 2 ◦ h = q 2 ◦ h ′ ) = ⇒ h = h ′ Since ◭◮ is w eaker than ⊳⊲ , the extended unicit y condition implies the unicity c o ndition of remark 6. Whenever the extended unicity condition holds, the sequential pro duct prop er ties can b e used as a definition of the s equential pro ducts, instead of definition 3.2. In addition, although this lo o ks like a m utually recur sive definition of the left and right sequential pro ducts, this recurs ivity has o nly tw o steps. Indeed, let ⋉ , ⋊ b e the seque ntial pro ducts and let f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 . First let h = f 1 ⋊ id X 2 . The right semi-pure pro duct pro p e rty states that q 1 ◦ h = f 1 ◦ p 1 and q 2 ◦ h ⊳ v 2 ◦ p 2 , thanks to the unicity condition this is a character ization of h . Now let k = f 1 ⋉ f 2 , from prop ositio n 1 5 w e get q 1 ◦ k ◭ f 1 ◦ p 1 and q 2 ◦ k = f 2 ◦ r 2 ◦ h , and thanks to the extended unicity condition this is a characterizatio n of k . 3.8 Some examples of Cartesian effect categor ies In this section and in se c tio n 4.4 we chec k that the effect categories from section 2.5 can b e seen a s Cartesian effect categ o ries. In ea ch example, fo r any pure morphism v and mor phis m f we build a morphism v ⋉ f , and it is left as an exercis e to chec k that v ⋉ f actually is the left semi-pur e product o f v and f . In addition, it happ ens tha t the extended unicity condition is satisfied, so that the sequential pro ducts ar e characterized by the sequential pro duct prop erties . Err ors . According to (Car b o ni et al., 1993), an extensive catego ry with pr o ducts is distributive. So, in the category C 0 , for all X , Y , Z the cano nical map from X × Y + X × Z to X × ( Y + Z ) is a n isomorphis m. Let v = J ( v 0 ) : X 1 Y 1 and f : X 2 → Y 2 in K , so that b y distributivity X 1 × X 2 is isomo r phic to ( X 1 × D [ f ] ) + ( X 1 × D [ f ] ). W e define v ⋉ f : X 1 × X 2 → Y 1 × Y 2 by D [ v ⋉ f ] = X 1 × D [ f ] , D [ v ⋉ f ] = X 1 × D [ f ] , [ v ⋉ f ] Y = v 0 × [ f ] Y and [ v ⋉ f ] E = [ f ] E ◦ π , where π : X 1 × D [ f ] → D [ f ] is the pro jection. D [ f ] [ f ] Y / /   Y 2   X 2 [ f ] / / = = Y 2 + E D [ f ] [ f ] E / / O O E O O X 1 × D [ f ] v 0 × [ f ] Y / /   Y 1 × Y 2   X 1 × X 2 [ v ⋉ f ] / / = = Y 1 × Y 2 + E X 1 × D [ f ] [ f ] E ◦ π / / O O E O O On sets, as exp ected, this provides the left sequential pro duct: ∀ x 1 ∈ X 1 , ∀ x 2 ∈ X 2 , ( f 1 ⋉ f 2 )( x 1 , x 2 ) =        h [ f 1 ]( x 1 ) , [ f 2 ]( x 2 ) i if [ f 1 ]( x 1 ) ∈ Y 1 and [ f 2 ]( x 2 ) ∈ Y 2 [ f 2 ]( x 2 ) if [ f 1 ]( x 1 ) ∈ Y 1 and [ f 2 ]( x 2 ) ∈ E [ f 1 ]( x 1 ) if [ f 1 ]( x 1 ) ∈ E 15 When E has one element a ll morphisms a re central, but as so on as E has more than one element there are non-central morphisms. Partiality . Given a categor y of partial morphisms , if we impose the existence of seque ntial pro ducts and the fact that a ll mor phisms are central, then w e get a notion that is rather similar to the notion o f p artial Cartesian catego ry o f pa rtial morphisms in (Cur ien a nd Obtulowitz, 19 89). On sets, up to adjunction, the left se quential pro duct is the same as for the monad X + 1: D ( f 1 ⋉ f 2 ) = D f 1 ⋉ D f 2 and ∀ x 1 ∈ D f 1 , ∀ x 2 ∈ D f 2 , ( f 1 ⋉ f 2 )( x 1 , x 2 ) = h [ f 1 ]( x 1 ) , [ f 2 ]( x 2 ) i . State . Let v = J ( v 0 ) : X 1 Y 1 and f : X 2 → Y 2 in K . Let us define v ⋉ f : X 1 × X 2 → Y 1 × Y 2 , up to the relev ant co mm utations, by [ v ⋉ f ] = v 0 × [ f ] : S × X 1 × Y 1 → S × Y 1 × Y 2 . X 1 v 0 / / Y 1 S × X 1 × X 2 [ v ⋉ f ] / / O O   = = S × Y 1 × Y 2 O O   S × X 2 [ f ] / / S × Y 2 On sets, as exp ected, this provides the left sequential pro duct: ∀ x 1 ∈ X 1 , ∀ x 2 ∈ X 2 , ∀ s ∈ S , [ f 1 ⋉ f 2 ]( s, x 1 , x 2 ) = h s 2 , y 1 , y 2 i where [ f 1 ]( s, x 1 ) = h s 1 , y 1 i and [ f 2 ]( s 1 , x 2 ) = h s 2 , y 2 i . The left seq uent ial pro duct f 1 ⋉ f 2 is usually distinct from the right seq ue ntial pro duct f 1 ⋊ f 2 . 4 Comparisons The use of stro ng monads for dealing with computational effects has bee n introduced b y Mog g i for r easoning ab out progr ams (Mog gi, 1989, 1991; W adler, 1 992). This has b een g eneralized by Pow er and Robinson, who defined F r eyd-c ate gories and proved that a strong monad is eq uiv alent to a F reyd-ca tegory with an adjunction (Po w er and Robinso n, 1997; Pow er and Thieleck e, 19 99). Independently , Arrows have b een introduced b y Hughes for genera lizing strong monads in Haskell (Hughes, 2 000; P aterson, 200 1); it was b elieved that Arrows are “ essentially” equiv alent to F reyd-categ ories, un til A tk ey pr ov ed that Arrows are in fact mor e general than F re y d catego ries (A tk ey, 2008). In this section we directly compar e each of these three framew orks to Ca r tesian effect categories: F reyd-categ ories in section 4.1, Ar rows in section 4 .2 and strong mo nads in section 4.3. Examples ar e conside r ed in section 4.4. 4.1 F reyd- categories In this section, it is prov ed that Car tes ian effect categories are F reyd-ca tegories (Pow er and Robinson, 1997; Po w er and Thielecke , 1 9 99; Selinger, 20 01). Let | K | deno te the s mallest wide sub categ ory of K , made of the ob jects and identities o f K . Definition 4.1. A binoidal c ate gory is a category K together with tw o functors ⊗ : | K | × K → K and ⊗ : K × | K | → K whic h coincide on | K | 2 (so that the notation ⊗ is not ambiguous). The functors ⊗ can be extended as tw o g raph homomorphisms ⋉ F r , ⋊ F r : K 2 → K , as follo ws. F or all f 1 : X 1 → Y 1 and f 2 : X 2 → Y 2 in K , le t: ( f 1 ⋉ F r f 2 = (id Y 1 ⊗ f 2 ) ◦ ( f 1 ⊗ id X 2 ) : X 1 ⊗ X 2 → Y 1 ⊗ Y 2 f 1 ⋊ F r f 2 = ( f 1 ⊗ id Y 2 ) ◦ (id X 1 ⊗ f 2 ) : X 1 ⊗ X 2 → Y 1 ⊗ Y 2 16 A morphism k 1 : X 1 → Y 1 is c entra l if for all f 2 : X 2 → Y 2 , k 1 ⋉ F r f 2 = k 1 ⋊ F r f 2 and symmetrically f 2 ⋉ F r k 1 = f 2 ⋊ F r k 1 . Let t : Φ ⇒ Ψ b e a natura l transforma tio n b etw een tw o functor s Φ , Ψ : K ′ → K , then t is c en t r al if every co mpo nent of t is central. In theor em 1 6 the gr aph homo mo rphisms ⋉ F r , ⋊ F r will b e r elated to the sequential pr o ducts ⋉ , ⋊ fro m section 3. In the next definition, “natural” means natura l in each comp onent sepa r ately . Definition 4.2. A symmetric pr emonoidal c ate gory is a binoidal categ ory K together with a n ob ject I o f K and central na tural is o morphisms with co mpo nents a X,Y ,Z : ( X ⊗ Y ) ⊗ Z → X ⊗ ( Y ⊗ Z ), l X : X ⊗ I → X , r X : I ⊗ X → X and c X,Y : X ⊗ Y → X ⊗ Y , sub ject to the usual coherence equations for symmetric monoidal categorie s (Mac La ne , 1997). Note that every symmetric monoidal ca tegory , hence every categor y with finite pro ducts, is s ymmetric premonoida l. A symmetric pr emonoidal functor betw een t wo symmetric pr emonoidal categorie s is a functor that preserves the partial functor ⊗ , the ob ject I a nd the natural isomo rphisms a, l , r, c . It is strict if in a ddition it maps central morphisms to central morphisms. A F re yd-c ate gory is an identit y- on-ob jects functor J : C → K where the catego ry C has finite pro ducts, the catego ry K is sy mmetr ic premonoidal and the functor J is strict s ymmetric premonoidal. The following result s tates that every Cartesia n effect catego ry is a F reyd-categ o ry . It is an eas y conse- quence of the r e s ults in section 3. Theorem 16. L et C j K b e a Cartesian effe ct c ate gory. L et a, l , r, c b e the natur al isomorphisms on C define d as in se ction 3.6. L et J : C → K b e the inclusion, let ⊗ : | K | × K → K and ⊗ : K × | K | → K b e the r est rictions of ⋉ and ⋊ , r esp e ctively, and let I = 1 . This f orms a F r eyd-c ate gory, whe r e ⋉ F r and ⋊ F r c oincide with ⋉ and ⋊ , r esp e ctively. Pr o of. The graph homomor phis ms ⊗ : | K | × K → K and ⊗ : K × | K | → K coincide on | K | 2 , a nd they are functors by theorem 12, hence K with ⊗ is a binoidal catego r y . Then, definitions 3.2 a nd 4.1 state that the graph homomorphisms ⋉ F r , ⋊ F r are the sequential pr o ducts ⋉ , ⋊ . It follows that both notions of central morphism (definitions 3.4 and 4.1) coincide. The fact tha t the transformations a, l , r, c are natur al, in the sense o f symmetric pr emonoidal ca tegories, is an immediate consequence of theo r em 1 4 (in fact fo r a it is lemma 13). Since all the comp onents of a, l, r, c are defined fro m the symmetric monoida l ca teg ory C , we know that they are isomorphisms a nd that they satisfy the coherence equa tions. In addition, since all pure morphisms a re c e n tral by theore m 9, it follows that a, l , r, c are central. Hence K with ⊗ , I a nd a, l , r, c is a symmetric premono idal category . Clearly the inclusion functor J : C → K is symmetric premono idal, and it is stric t b eca use of theorem 9. 4.2 Arrows In view of the similarities b etw een F rey d-categor ies and Arrows, it can b e gues sed that every Cartesian effect category gives rise to a n Arrow (Hughes, 2 000; Paterson, 2001); this is stated in this sectio n. Definition 4.3. An Arr ow typ e is a binary type co nstructor A of the for m: class Arrow A where arr :: ( X → Y ) → A X Y ( > > > ) :: A X Y → A Y Z → A X Z first :: A X Y → A ( X , Z ) ( Y , Z ) satisfying the following equa tions: (1) arr id > > > f = f (2) f > > > arr id = f (3) ( f > > > g ) > > > h = f > > > ( g > > > h ) (4) arr ( w .v ) = arr v > > > ar r w (5) first ( arr v ) = arr ( v × id) (6) first ( f > > > g ) = first f > > > fir st g (7) first f > > > arr (id × v ) = arr (id × v ) > > > fir st f (8) first f > > > arr fst = arr fst > > > f (9) first ( firs t f ) > > > ar r asso c = arr ass oc > > > f irst f 17 where the functions ( × ), fst and ass oc are defined as: ( × ) :: ( X → X ′ ) → ( Y → Y ′ ) → ( X , Y ) → ( X ′ , Y ′ ) such that ( f × g )( x, y ) = ( f x, g y ) fst :: ( X, Y ) → X such that fst ( x, y ) = x assoc :: (( X , Y ) , Z ) → ( X, ( Y , Z )) suc h that assoc (( x, y ) , z ) = ( x, ( y , z )) Let C H denote the category of Haskell t ypes and or dinary functions, so that the Haskell notation ( X → Y ) represents C H ( X, Y ), made o f the Hask ell ordinary functions from X to Y . An arrow A constructs a t y p e A X Y for all t yp es X and Y . W e slightly mo dify the definition of Arr ows b y allowing ( X → Y ) to represent C ( X , Y ) for any Ca rtesian category C and by requir ing tha t A X Y is a s e t r ather than a type: more on this issue can be found in (At key, 2 008). In addition, we use ca tegorical notations instead of Haskell sy ntax. F or this reason, from no w o n, for an y Cartesian category C , an Arr ow A on C asso cia tes to each o b jects X , Y of C a set A ( X , Y ), tog ether with thr e e o pe r ations: arr : C ( X , Y ) → A ( X, Y ) , > > > : A ( X, Y ) → A ( Y , Z ) → A ( X , Z ) , first : A ( X , Y ) → A ( X × Z, Y × Z ) , t hat satisfy the eq uations (1 )– (9). Basically , the corres p o ndence b etw een a Ca rtesian effect categor y C j K and an Arrow A o n C identifies K ( X , Y ) with A ( X, Y ) for a ll types X and Y . This is stated more precis e ly in prop osition 17. Prop ositi o n 17. Every Cartesian effe ct c ate gory C j K gives rise t o an Arr ow A on C , ac c or ding to the fol lowing table: Cartesian effe ct c ate gories Arr ows K ( X, Y ) A ( X, Y ) C ( X , Y ) ⊆ K ( X , Y ) arr : C ( X , Y ) → A ( X, Y ) f 7→ ( g 7→ g ◦ f ) > > > : A ( X , Y ) → A ( Y , Z ) → A ( X , Z ) f 7→ f × id first : A ( X , Y ) → A ( X × Z , Y × Z ) Pr o of. The fir st and second line in the table sa y that A ( X, Y ) is made o f the morphisms fro m X to Y in K and that arr is the conversion from pure morphisms to a r bitrary mo rphisms. The third and fourth lines say that > > > is the (re verse) comp osition of morphisms and that fi rst is the right semi-pure pro duct with the identit y . Now we prove that A is an Arrow b y transla ting ea ch pr op erty (1)–(9) in terms of Ca rtesian effect categor ie s and giving the argument for its pro o f. Note that fst is the common name for pro jections like p 1 , q 1 , . . . (in section 3) and that asso c is the na tural isomor phism a a s in section 3.6. (1) f ◦ id = f ident ity in K (2) id ◦ f = f identit y in K (3) h ◦ ( g ◦ f ) = ( h ◦ g ) ◦ f asso ciativity in K (4) w ◦ v in C = w ◦ v in K C ⊆ K is a functor (5) v × id in C = v × id in K × in K e x tends × in C (6) ( g ◦ f ) × id = ( g × id) ◦ ( f × id) lemma 1 0 (7) (id × v ) ◦ ( f × id) = ( f × id) ◦ (id × v ) theor em 9 (8) q 1 ◦ ( f × id) = f ◦ p 1 definition 3.1 (9) a ◦ (( f × id) × id) = ( f × id) ◦ a lemma 13 The Ar r ow combinators sec ond , ( ∗ ∗ ∗ ) and (& & &) can b e derived from arr , ( > > > ) and f irst , see e.g (Hughes, 20 00; Paterson, 2001). The corr esp ondence in prop os itio n 17 is easily e x tended to these functions . The left pair ing h f 1 , f 2 i l and the na tur al isomorphism c (cor r esp onding to swa p ) a re defined in se c tion 3.3 and 3.6, resp ectively . Cartesian effect ca tegories Arrows ( id × f ) = c ◦ ( f × id ) ◦ c second f = arr swap > > > fi rst f > > > a rr swap f 1 ⋉ f 2 = (id × f 2 ) ◦ ( f 1 × id) f 1 ∗ ∗ ∗ f 2 = fi rst f 1 > > > s econd f 2 h f 1 , f 2 i l = ( f 1 ⋉ f 2 ) ◦ h id , id i f 1 & & & f 2 = ar r ( λx → ( x, x )) > > > ( f 1 ∗ ∗ ∗ f 2 ) 18 F or instance in (Hughes , 2000, § 4.1) it is s tated that & & & is no t a categorical pr o duct since in gener al f 1 is different from ( f 1 & & & f 2 ) > > > arr fst : “ ther e is no r e ason to exp e ct Haskel l’s p air typ e, & & & , to b e a c ate goric al pr o duct in the c ate gory of arr ows, or inde e d to exp e ct any c ate goric al pr o duct to ex ist ”. W e can state this more precisely in a Cartesian effect catego ry , where ( f 1 & & & f 2 ) > > > a rr f st corresp onds to q 1 ◦ h f 1 , f 2 i l . Indeed, b oth morphisms are c onsistent: it follows fr o m prop ositio n 15 and pur e subs titution that q 1 ◦ h f 1 , f 2 i l ◭ f 1 . 4.3 Strong monads Strong monads corres po nd to F reyd-ca teg ories J : C → K with a right a djoint for J (Pow er and Robinson, 1997), while Cartesian effect categories cor resp ond to F reyd-categor ies with a sequential pro duct (theo- rem 16). In this section, w e giv e a condition which c haracterizes the strong mo na ds such that the corre- sp onding F r eyd-catego ry is a we ak Cartesian effect categor y , which mea ns that there are tw o g raph homo- morphisms ⋉ : C × K → K and ⋊ : K × C → K which sa tisfy the left and right semi- pur e pro duct prop erty resp ectively , but which may not b e uniq ue . W e use the same nota tions as in remar k 1. It has b een seen in remark 2 that the effect of a morphism f : X → Y of K stands for [ h i Y ◦ f ] = M h i Y ◦ [ f ] : X → M 1 in C 0 , s o that in C 0 : ∀ ϕ : X → M Y , ∀ ϕ ′ : X → M Y ′ , ϕ ≈ 0 ϕ ′ ⇐ ⇒ M h i Y ◦ ϕ = M h i Y ′ ◦ ϕ ′ . Let ⊳ be a consis tency r e lation on C j K , then the r elation ⊳ 0 in C 0 is defined by [ f ] ⊳ 0 [ v ] ⇐ ⇒ f ⊳ v , or equiv a lent ly: ∀ ϕ, ϕ ′ : X → M Y in C 0 , ϕ ⊳ 0 ϕ ′ ⇐ ⇒ ∃ v 0 : X → Y in C 0 , ( ϕ ′ = η Y ◦ v 0 ) ∧ (] ϕ [ ⊳ J ( v 0 )) . The pure substitution pro p erty of ⊳ (prop o s ition 3) corresp onds to the following substitution pr op erty of ⊳ 0 : ∀ v 0 : X → Y , ∀ w 0 : Y → Z , ∀ ψ : Y → M Z , ψ ⊳ 0 η Z ◦ w 0 = ⇒ ψ ◦ v 0 ⊳ 0 η Z ◦ w 0 ◦ v 0 . Now in addition let us assume that C 0 , hence C , is Ca rtesian. In (Mog gi, 19 89), it is explained why the monad ( M , µ, η ) and the product × are not sufficient for dealing with several v ariables: there is a typ e mismatch fro m Y 1 × M Y 2 to M ( Y 1 × Y 2 ). This issue is solved by adding a str ength , i.e., a natural transformatio n t with co mpo nent s t Y 1 ,Y 2 : Y 1 × M Y 2 → M ( Y 1 × Y 2 ) sa tisfying four axio ms (Mogg i, 19 89). One of these axioms is that for all X , r M X = M r X ◦ t 1 ,X : 1 × M X → M X , where the natural iso morphism r is made o f the pro jections r X : 1 × X → X as in section 3.6. Let us a ssume that we ar e giv en a strength t for our monad. In K , let v : X 1 Y 1 and f : X 2 → Y 2 ; in order to form a kind of product of v and f , the usual metho d cons ists in co mp o sing in C 0 the pro duct v 0 × [ f ] : X 1 × X 2 → Y 1 × M Y 2 with the streng th t Y 1 ,Y 2 : Y 1 × M Y 2 → M ( Y 1 × Y 2 ); we call this construction the left Kleisli pr o duct . The right Kleisli pro duct is defined symmetrically . Definition 4.4 . F or all v = J ( v 0 ) : X 1 Y 1 and f : X 2 → Y 2 in K , the left Kleisli pr o duct of v and f in K is defined by: [ v ⋉ Kl f ] = t Y 1 ,Y 2 ◦ ( v 0 × [ f ]) : X 1 × X 2 → M ( Y 1 × Y 2 ) in C 0 . Lemma 18. The stre ngth c an b e expr esse d as a left Kleisli pr o duct: ] t Y 1 ,Y 2 [= id Y 1 ⋉ Kl ]id M Y 2 [ in K . F or al l Y 1 , Y 2 , with pr oje ctions q 2 : Y 1 × Y 2 Y 2 and q ′ 2 : Y 1 × M Y 2 M Y 2 : q 2 ◦ ] t Y 1 ,Y 2 [= q ′ 2 in K . Pr o of. In K , let v = id Y 1 : Y 1 Y 1 and f =]id M Y 2 [: M Y 2 → Y 2 , so that v 0 = id Y 1 and [ f ] = id M Y 2 in C 0 . Then v 0 × [ f ] = id Y 1 × M Y 2 so that [ v ⋉ Kl f ] = t Y 1 ,Y 2 , this is the first prop er t y . Now, for reada bilit y , we omit the subscript 0 for naming the pr o jections in C 0 . The result is equiv alen t to M q 2 ◦ t Y 1 ,Y 2 = q ′ 2 in C 0 . The 19 pro jection q 2 can b e dec o mp o sed as q 2 = r 2 ◦ ( h i Y 1 × Y 2 ), w he r e r 2 = r Y 2 : 1 × Y 2 → Y 2 is the pr o jection. Hence on the one hand M q 2 = M r 2 ◦ M ( h i Y 1 × Y 2 ), and on the other hand q ′ 2 = r ′ 2 ◦ ( h i Y 1 × M Y 2 ) where r ′ 2 = r M Y 2 : 1 × M Y 2 → M Y 2 is the pro jection. Y 1 × M Y 2 q ′ 2 = ) ) h i× M id   t Y 1 ,Y 2 / / = M ( Y 1 × Y 2 ) M ( h i× id)   M q 2 = u u 1 × M Y 2 r ′ 2   t 1 ,Y 2 / / = M (1 × Y 2 ) M r 2   M Y 2 id / / M Y 2 In the previous diagra m, the square on the top is commutativ e since t is natural, and the square on the bo ttom is commutativ e thanks to the pro p er ty of the streng th with resp ect to r . Hence the lar ge squa re is commutativ e , a nd the result follows. Theorem 1 9 . L et C 0 b e a Cartesian c ate gory with a str ong monad ( M , µ, η , t ) and with a c onsistency r elation ⊳ on C j K . Then C 0 with the left and right Kleisli pr o ducts is a we ak Cartesian effe ct c ate gory if and only if for al l Y 1 , Y 2 (with the pr oje ctions q 1 : Y 1 × Y 2 → Y 1 and q ′ 1 : Y 1 × M Y 2 → Y 1 ): q 1 ◦ ] t Y 1 ,Y 2 [ ⊳ q ′ 1 in K , or e quivalently M q 1 ◦ t Y 1 ,Y 2 ⊳ 0 η Y 1 ◦ q ′ 1 in C 0 . If in addition ∀ ϕ, ϕ ′ : X → M ( Y 1 × Y 2 ) in C 0 , ( M q 1 ◦ ϕ ⊳ ⊲ 0 M q 1 ◦ ϕ ′ ) ∧ ( M q 2 ◦ ϕ = M q 2 ◦ ϕ ′ ) = ⇒ ϕ = ϕ ′ in C 0 , then C 0 with the left and right Kleisli pr o ducts is a Cartesian effe ct c ate gory. Roughly sp eaking (i.e., forg etting the pro jections), this means that C 0 with the Kle is li pro ducts is a weak Cartesian effect catego ry if and only if: the streng th o f the monad is cons is tent with the identit y . Pr o of. Let us consider t he morphism ] t Y 1 ,Y 2 [. By the first part of lemma 18 ] t Y 1 ,Y 2 [= id Y 1 ⋉ Kl ]id M Y 2 [. Therefore, if the left Kle isli pro duct do es satisfy the left semi-pure pro duct prop er t y , then q 1 ◦ ] t Y 1 ,Y 2 [ ⊳ q ′ 1 . Now, let us a ssume that q 1 ◦ ] t Y 1 ,Y 2 [ ⊳ q ′ 1 ; this is illustra ted b elow, together with q 2 ◦ ] t Y 1 ,Y 2 [= q ′ 2 (second part of lemma 18), first in K then in C 0 : Y 1 id / / /o /o /o /o /o /o /o /o /o /o Y 1 Y 1 × M Y 2 q ′ 1 O O O O q ′ 2   O O ] t [ / / = ⊳ Y 1 × Y 2 q 1 O O O O q 2   O O M Y 2 ]id[ / / Y 2 Y 1 η / / M Y 1 Y 1 × M Y 2 q ′ 1 O O q ′ 2   t / / = ⊳ 0 M ( Y 1 × Y 2 ) M q 1 O O M q 2   M Y 2 id / / M Y 2 F or a ny v : X 1 Y 1 and f : X 2 → Y 2 , the morphism v ⋉ Kl f in K is defined by [ v ⋉ Kl f ] = t Y 1 ,Y 2 ◦ ( v 0 × [ f ]) in C 0 . In the diag ram b elow, in C 0 , the left-hand side illustra tes the bina ry pro duct prop erty of v 0 × [ f ] and 20 the right-hand side is a s ab ov e. X 1 v 0 / / [ v ] = * * Y 1 η / / M Y 1 X 1 × X 2 p 1 O O p 2   v 0 × [ f ] / / = = Y 1 × M Y 2 q ′ 1 O O q ′ 2   t / / = ⊳ 0 M ( Y 1 × Y 2 ) M q 1 O O M q 2   X 2 [ f ] / / [ f ] = 4 4 M Y 2 id / / M Y 2 It follows immediately from the b otto m part o f this diag ram that M q 2 ◦ [ v ⋉ Kl f ] = [ f ] ◦ p 2 , which means that q 2 ◦ ( v ⋉ Kl f ) = f ◦ p 2 in K . Moreov er, it follows from the top part, using the s ubstitution prop erty of ⊳ 0 , that M q 1 ◦ [ v ⋉ Kl f ] ⊳ 0 [ v ] ◦ p 1 , which means that q 1 ◦ ( v ⋉ Kl f ) ⊳ v ◦ p 1 in K . The left semi-pur e pro duct prop erty is hence satisfied by ⋉ Kl . Then the last par t o f the theorem follows immediately from remark 6. 4.4 More examples of Cartesian effect categories In this s e ction we consider the effect categ ories in section 2 .5 whic h ar e defined from a s tr ong monad. In each example the strength is describ ed, then it is easy to ch eck that the conditions of theorem 19 are satisfied, so tha t the Kleisli categor y g ives rise to a cartesian effect categ ory with the Kleisli pro ducts as semi-pure pro ducts. Ho wev e r , for the monads of lists and of finite (multi) sets, the extended consistency relatio n is so weak that the sequential pr o duct prope r ties (definition 3.5) are no t sufficien t for c haracterizing the sequen tial pro ducts. Err ors . The str ength t X 1 ,X 2 is obtained by composing the isomorphism X 1 × ( X 2 + E ) ∼ = ( X 1 × X 2 ) + ( X 1 × E ) with id X 1 × X 2 + σ X 1 : ( X 1 × X 2 ) + ( X 1 × E ) → ( X 1 × X 2 ) + E , where σ X 1 is the pro jection. The Kleisli pro ducts are semi-pur e pro ducts from section 3.8. Lists . The strength is such that for all x 1 ∈ X 1 and x 2 = ( x 2 , 1 , . . . , x 2 ,k ) ∈ L ( X 2 ), t X 1 ,X 2 ( x 1 , x 2 ) = ( h x 1 , x 2 , 1 i , . . . , h x 1 , x 2 ,k i ). It follows tha t M p 1 ◦ t X 1 ,X 2 ( x 1 , x 2 ) = ( x 1 ) k while η X 1 ◦ p ′ 1 ( x 1 , x 2 ) = ( x 1 ). So, the left sequential pro duct is: ∀ x 1 ∈ X 1 , ∀ x 2 ∈ X 2 , ( f 1 ⋉ f 2 )( x 1 , x 2 ) = ( h y 1 , z 1 i , . . . , h y 1 , z p i , . . . , h y n , z 1 i , . . . , h y n , z p i ) , where f 1 ( x 1 ) = ( y 1 , . . . , y n ) and f 2 ( x 2 ) = ( z 1 , . . . , z p ), so that there are non-central morphisms. Finite (mu lti)sets . Finite multisets and finite s ets ha ve similar prop erties. F or sets, the strength is such that for all x 1 ∈ X 1 and x 2 ∈ P fin ( X 2 ), t X 1 ,X 2 ( x 1 , x 2 ) = {h x 1 , x ′ i | x ′ ∈ x 2 } , and both the left and the rig ht sequential pro duct ar e : ∀ x 1 ∈ X 1 , ∀ x 2 ∈ X 2 , ( f 1 ⋉ f 2 )( x 1 , x 2 ) = ( f 1 ⋊ f 2 )( x 1 , x 2 ) = {h y , z i | y ∈ f 1 ( x 1 ) ∧ z ∈ f 2 ( x 2 ) } . 5 Conclusion This pa pe r deals with the ma jor issue of formalizing computational effects, especia lly while using multiv ariate functions. F or this purp ose, we hav e intro duced sev eral new features: first a c onsistency relation and the asso ciated notio n of effe ct c ate gory , then the semi-pur e and se quential pro ducts for getting a Cartesian effe ct c ate gory . Thank s to the universal prop erty of the semi-pure pro ducts, each Cartesia n effect catego ry is 21 endow e d with a powerful too l for definitions and pro ofs. This has been used for proving that every Cartesian effect categor y is a F reyd-ca tegory and for giving conditions which ensur e that a stro ng monad gives rise to a Cartesian effect categor y . W e hav e s tudied several ex amples of effects, in each cas e we get a Cartes ian effect categor y . Since the notio ns of e ffect c a tegory and Ca rtesian effect category are new, there is still a large amount of work to do in order to study their applications and their limitations. F or instance, in or der to define some kind of clo sure, o ne could try to gener alize the r esults of (Curien and Obtulowitz, 19 8 9) on par tiality to other effects. F urther investigations include: enhancing the comparison with (Moggi, 1995) in orde r to clarify the rela tio ns b etw een Car tesian effect categor ies and ev aluation logic; fitting mor e ex amples in our framework (e.g. contin uations). In a ddition, the is sue of co mbining effects, as in (Hyland et al., 2006), mig h t be revisited from the p oint of view of effect categor ies. Ac knowledgmen ts The a uthors would like to thank Eugenio Mogg i for p ointing o ut the pa p e r s (Curien and Obtulowitz, 1 989) and (Moggi, 199 5). References A tkey , R., 200 8 . What is a categorical mo del of arrows? In: Mathematically Structured F unctional Pro- gramming (MSFP’08). Carb oni, A., Lack, S., W alter s , R., 19 93. Intro duction to extensiv e and distributive categories. Journal o f Pure and Applied Algebra 8 4, 145– 158. Curien, P .-L., Obtulowitz, A., 19 89. Partialit y , cartesian closedness and top oses. Informa tion and Computa- tion 80, 50–9 5. Dumas, J.-G., Duv al, D., Reynaud, J .-C., 2007 . Sequential pro ducts in effect categor ies. URL http: //arx iv.or g/abs/0707.1432 Duv al, D., Reynaud, J .-C., 20 05. Diagrammatic lo gic and ex ceptions: an intro duction. In: Dagstuhl Seminar Pro ceeding s - MAP05 , Ma thematics, Algorithms, Pr o ofs. URL http: //www .dags tuhl.de/05021/Materials/ Heunen, C., Jacobs, B., 2006 . Arrows, like monads, are monoids. Electronic Notes in Theor etical Computer Science 158 , 21 9–236 . Hughes, J., 20 00. Gener alising monads to arr ows. Science of Computer Pr ogra mming 37, 67– 1 11. Hyland, M., Plotkin, G., Pow er, J., 2006 . Combining effects: Sum and tensor. Theo r etical Co mputer Science 357, 70–9 9 . Mac Lane, S., 19 97. Categories for the W ork ing Mathematicia n, 2nd edition. V ol. 5 of Gr aduate T exts in Mathematics. Springer V erlag. Moggi, E., 1989. Computational lambda-calculus a nd monads. In: Logic In Computer Science (LICS). IEE E Press, pp. 14– 23. Moggi, E., 19 91. No tions of computation and mona ds. Information and Computation 93, 5 5–92. Moggi, E., 19 95. A sema n tics for ev alua tion logic. F undamenta Informaticae 22, 11 7–15 2. Paterson, R., 2 001. A new notation for arr ows. In: International Conference o n F unctional Pro gramming. A CM, pp. 22 9–240 . 22 Po w er, J., Robinson, E ., 1 997. Premo noidal categories and notions of computation. Mathematica l Structures in Computer Science 7 , 453–4 68. Po w er, J., Thieleck e, H., 1999. Closed Fre yd- and κ -categ ories. In: In t. Co ll. on Automata, Languag e s and Progr amming (ICALP’99 ). V o l. 1644 of LNCS. Spr inger V erlag , pp. 625–6 34. Selinger, P ., 2 001. Control categor ie s a nd dua lit y: on the categorica l semantics of the lambda-mu calculus. Mathematical Structures in Co mputer Science 11 , 2 07–2 60. W adler, P ., 1992 . The essence of functional progra mming. In: 1 9th Sy mp os ium on Principle s of Progra mming Languages . ACM. 23

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment