sequential products in effect categories
play

Sequential products in effect categories Jean-Guillaume Dumas, - PowerPoint PPT Presentation

Sequential products in effect categories Jean-Guillaume Dumas, Dominique Duval, Jean-Claude Reynaud work in progress Journ ees ARROWS Nancy June 7., 2007 Outline Introduction Examples Cartesian categories Cartesian effect categories


  1. Sequential products in effect categories Jean-Guillaume Dumas, Dominique Duval, Jean-Claude Reynaud work in progress Journ´ ees ARROWS Nancy — June 7., 2007

  2. Outline Introduction Examples Cartesian categories Cartesian effect categories Conclusion

  3. The problem In some languages, like C , the order of evaluation of function arguments is unspecified. ◮ when there is no computational effect, the order of evaluation does not matter ◮ when effects do occur, the order of evaluation becomes fundamental e.g. a[i]=++i; The problem is to design a formal framework for imposing an evaluation order

  4. Some solutions The language Haskell provides a framework for dealing with computational effects: ◮ Monads [Moggi 91, Wadler 93] with generalizations: ◮ Freyd categories [Power-Robinson 97] ◮ Arrows [Hughes 00] Comparisons [Heunen-Jacobs 06]: “all are monoids”: Monads “are” Arrows “are” Freyd categories

  5. Sequentialization ◮ without effects, the function: ( 1 ) ( a 1 , a 2 ) �→ ( f 1 ( a 1 ) , f 2 ( a 2 )) can be decomposed as: ( 2 ) ( a 1 , a 2 ) �→ ( f 1 ( a 1 ) , a 2 ) �→ ( f 1 ( a 1 ) , f 2 ( a 2 )) ◮ with effects, ( 1 ) is ambiguous, but ( 2 ) is not: “compute first f 1 ( a 1 ) , then f 2 ( a 2 ) ” So, the issue is about: ( a 1 , a 2 ) �→ ( f ( a 1 ) , a 2 ) “compute f ( a 1 ) and keep the information about a 2 ” ◮ strength for Monads ◮ premonoidal category for Freyd categories ◮ first operator for Arrows

  6. Our solution Like the other frameworks, we distinguish two kinds of functions: ◮ (general) functions → : maybe with effect ◮ pure functions � : effect-free pure functions are functions cf. [Moggi 91]: values are computations Unlike the other frameworks, we distinguish two kinds of equations: ◮ (strong) equations ≡ : for equalities ◮ semi-equations � : some kind of “local comparability” strong equations are semi-equations

  7. Outline Introduction Examples Cartesian categories Cartesian effect categories Conclusion

  8. Two examples ◮ Partiality – can be handled with the monad X �→ X + 1 – our semi-equations form an partial order relation ◮ State – can be handled with the monad X �→ ( S × X ) S – our semi-equations form an equivalence relation

  9. � � � � � � � � � � � ��� � � ��� � � � � ��� � � ��� Partiality Two kinds of functions: ◮ general functions may be partial ◮ pure functions are total functions Two kinds of equations: ◮ an equation f ≡ g is an equality (of domains and values) ◮ a semi-equation f � g is a (usual) inequality: D ( f ) ⊆ D ( g ) and f ( x ) = g ( x ) for all x ∈ D ( f ) . Key property: f � f ( x 1 ) or ⊥ x 1 � ≡ � � ( x 1 , x 2 ) ( f ( x 1 ) , x 2 ) or ⊥ � � � id x 2 � x 2 or ⊥

  10. � � ��� � � � � � � � � � � � ��� � ��� � � ��� State Two kinds of functions: ◮ general functions may use and modify the state ◮ pure functions neither use nor modify the state Two kinds of equations: ◮ an equation f ≡ g is an equality ◮ a semi-equation f � g (or f ∼ = g ) only means that the resulting values are equal: f ( s , x ) = ( s ′ , y ) , g ( s , x ) = ( s ′′ , y ) with the same y . Key property: f � f ( s , x 1 ) = ( s ′ , y 1 ) ( s , x 1 ) � ≡ � � ( s ′ , y 1 , x 2 ) ( s , x 1 , x 2 ) � � � id ( s , x 2 )( � =)( s ′ , x 2 ) ( s , x 2 ) �

  11. Outline Introduction Examples Cartesian categories Cartesian effect categories Conclusion

  12. Multivariate functions: f ( x 1 , . . . , x n ) ◮ “Logical” view: several arguments: x 1 , . . . , x n ◮ “Categorical” view: one argument: � x 1 , . . . , x n � f ( x 1 , . . . , x n ) = f ( � x 1 , . . . , x n � ) Substitution is split in two parts: 1. formation of the tuple t = � t 1 , . . . , t n � 2. substitution of one argument f ( t )

  13. � � � Categories Categories = the framework for substituting one argument f ( t ) = f . t Definition A category is a graph with composition: g g f f � Y � Z � Z X X Y ��� − → g . f ��� X X id X − → generalizing monoids: h . ( g . f ) ≡ ( h . g ) . f , f . id ≡ f , id . f ≡ f .

  14. Words drawings graphs categories computer sc. point vertex object type arrow edge morphism function All functions are univariate!

  15. � � � � � � (Categorical) Products An abstraction of the cartesian product of sets (here, n = 2) Y 1 Y 1 � � � � f 1 � � f 1 � � � � � q 1 � � � � � � � ≡ � � � � ��� � � f 1 , f 2 � � Y 1 × Y 2 � � − → � X X � � � � � � � � ≡ � � � � � � q 2 � � � � f 2 � � f 2 � � � � � � Y 2 Y 2

  16. � � � � � � � � � � Multivariate functions 1. formation of the tuple t = � t 1 , . . . , t n � 2. substitution of one argument f ( t ) Y 1 Y 1 t 1 t 1 � � � � � � � � � � � � ≡ � ��� � f f � � Z � � Z − → � � Y 1 × Y 2 Y 1 × Y 2 X X � � � � ≡ � � � � � � � � � � t 2 � t 2 � � � Y 2 Y 2 f . � t 1 , t 2 � f ( t 1 , . . . , t n ) = f . � t 1 , . . . , t n �

  17. Cartesian categories Cartesian categories = the framework for substituting several arguments f ( t 1 , . . . , t n ) = f . � t 1 , . . . , t n � Definition A cartesian category is a category with products.

  18. Outline Introduction Examples Cartesian categories Cartesian effect categories Conclusion

  19. Effect categories (1/2) Definition An effect category is a decorated category: ◮ two kinds of functions: – (general) functions → – pure functions � every pure function is a function identities are pure, composition of pures is pure ◮ two kinds of equations: – (strong) equations ≡ – semi-equations � every equation is a semi-equation on pure functions, � and ≡ coincide and. . .

  20. Effect categories (2/2) . . . and in addition: ◮ � satisfies substitution: if g 1 � g 2 : Y → Z then g 1 . f � g 2 . f ◮ � satisfies replacement only for pure functions: if g 1 � g 2 : Y → Z and v pure then v . g 1 � v . g 2

  21. Examples ◮ partiality C is the category of partial functions pure functions are total functions f ≡ g means f = g (equality of domains and values) f � g means D ( f ) ⊆ D ( g ) and f ( x ) = g ( x ) for all x ∈ D ( f ) . ◮ state S is the set of states C is the category with points S × X and with all functions pure functions are id S × v : ( s , x ) �→ ( s , v ( x )) f ≡ g means f = g f � g means f and g return the same value y ∈ Y , maybe not the same state!

  22. � � � � � � � � � � � � � � � � � � � � � ��� � ��� Semi-products A semi-product is a decorated product it defines � f 1 , f 2 � only when f 2 is pure Y 1 Y 1 � � � � f 1 � � f 1 � � � � � q 1 � � � � � � � � ≡ � � � ��� � � f 1 , f 2 � � Y 1 × Y 2 � � − → � X X � q 2 f 2 f 2 Y 2 Y 2 Identities are pure! Hence, we get: � f , id � : ( a 1 , a 2 ) �→ ( f ( a 1 ) , a 2 ) “compute f ( a 1 ) and keep the information about a 2 ”

  23. Examples ◮ partiality � f 1 , f 2 � ( x 1 , x 2 ) = ( f ( x 1 ) , x 2 ) when x 1 ∈ D ( f ) = ⊥ when x 1 �∈ D ( f ) ◮ state � f 1 , f 2 � ( s , x 1 , x 2 ) = ( s ′ , y 1 , y 2 ) where f 1 ( s , x 1 ) = ( s ′ , y 1 ) and f 2 ( s , x 2 ) = ( s , x 2 )

  24. � � � ��� � � � ��� � � ��� � � � ��� � ��� � � ��� � � � � � � � � � � � � � � � � � � Sequential product “compute first f 1 ( a 1 ) , then f 2 ( a 2 ) ” Definition f 1 ⋉ f 2 = ( id Y 1 × f 2 ) . ( f 1 × id X 2 ) f 1 id � Y 1 X 1 Y 1 p 1 s 1 � q 1 ≡ f 1 × id id × f 2 X 1 × X 2 Y 1 × X 2 Y 1 × Y 2 p 2 � s 2 ≡ q 2 f 2 id � Y 2 X 2 X 2

  25. � � � � � � � � � � � � � � � � � � � � ����� � � � � � � � � � � � � � � � � � � � � � � � � � A sequential product is a “weak product” Theorem For each f 1 : X 1 → Y 1 , f 2 : X 2 → Y 2 and pure values x 1 : U � X 1 and x 2 : U � X 2 : q 1 . ( f 1 ⋉ f 2 ) . � x 1 , x 2 � � f 1 . x 1 q 2 . ( f 1 ⋉ f 2 ) . � x 1 , x 2 � ≡ f 2 . x 2 . � � . f 1 . x 1 x 1 f 1 � Y 1 X 1 U � q 1 � x 1 , x 2 � f 1 ⋉ f 2 X 1 × X 2 Y 1 × Y 2 U x 1 f 1 � Y 1 U X 1 q 2 ≡ � � � x 2 f 2 � Y 2 X 2 U

  26. Decorated results and proofs By forgetting the decorations: ◮ every decorated result remains a result ◮ every decorated proof remains a proof By adding decorations: ◮ some results can be decorated, maybe in several ways, ◮ and for these results, some proofs can be decorated

Recommend


More recommend