a metalanguage for guarded iteration
play

A Metalanguage for Guarded Iteration Sergey Goncharov Christoph - PowerPoint PPT Presentation

A Metalanguage for Guarded Iteration Sergey Goncharov Christoph Rauch Lutz Schr oder Friedrich-Alexander-Universit at Erlangen-N urnberg ICTAC 2018, October 15-19, Stellenbosch Two Flavors of Computations Domain theory


  1. A Metalanguage for Guarded Iteration Sergey Goncharov Christoph Rauch Lutz Schr¨ oder Friedrich-Alexander-Universit¨ at Erlangen-N¨ urnberg ICTAC 2018, October 15-19, Stellenbosch

  2. ❼ ❼ ❼ Two Flavors of Computations Domain theory ❼ Computations are identified with final result (if any) ❼ Programs either terminate with a value, or they diverge ❼ Extensional paradigm : 1/18

  3. Two Flavors of Computations Domain theory ❼ Computations are identified with final result (if any) ❼ Programs either terminate with a value, or they diverge ❼ Extensional paradigm : Process algebra ❼ Computations are processes unfolding in time ❼ Behavioural semantics, potentially disregarding final result ❼ Intensional paradigm : : Abramsky 2014, Intensionality, Definability and Computation 1/18

  4. Two Flavors of Computations Domain theory ❼ Computations are identified with final result (if any) ❼ Programs either terminate with a value, or they diverge ❼ Extensional paradigm : Process algebra ❼ Computations are processes unfolding in time ❼ Behavioural semantics, potentially disregarding final result ❼ Intensional paradigm : Here Unified semantic framework for iterative computations : Abramsky 2014, Intensionality, Definability and Computation 1/18

  5. Guardedness General idea Ensure progress or productivity in (co)recursive definitions In process algebra ❼ Recursive process specification X “ t guarded if every occurrence of X in t is under an action ❼ E.g. in CCS under bisimulation semantics: guarded recursive specifications have unique solutions [Milner, 1989] ❼ For example, P “ a . P keeps performing the action a 2/18

  6. Guardedness General idea Ensure progress or productivity in (co)recursive definitions More recently: in (co)programming ❼ Guardedness analysis in Coq for corecursive definitions, proofs by corecursion: Do corecursive calls occur under constructors? [Coquand, 1994] ❼ Guarded recursion by typing/functorial guardedness [Birkedal and Møgelberg, 2013], [Milius and Litak, 2017], [Clouston, Bizjak, Grathwohl, and Birkedal, 2015] and many others Abstract guardedness Unifying notion both for guarded recursion and for guarded iteration via guarded traced monoidal categories [Goncharov and Schr¨ oder, 2018] 2/18

  7. (Abstractly) Guarded co-Cartesian Categories Inference rules f : X Ñ Y f : X Ñ σ Z g : Y Ñ σ Z in 1 f : X Ñ in 2 Y ` Z r f , g s : X ` Y Ñ σ Z f : X Ñ in 2 Y ` Z g : Y Ñ σ V h : Z Ñ V r g , h s f : X Ñ σ V Definition (Guarded co-Cartesian category) A co-Cartesian category C equipped with distinguished subsets Hom σ p X , Y q Ď Hom p X , Y q of partially guarded morphisms for A , B P | C | , and any summand σ : Y 1 Ñ Y 1 ` Y 2 » Y satisfying the rules above is called guarded ( f : X Ñ σ Y means f P Hom σ p X , Y q ) 3/18

  8. (Abstractly) Guarded co-Cartesian Categories Inference rules f : X Ñ Y f : X Ñ σ Z g : Y Ñ σ Z in 1 f : X Ñ 2 Y ` Z r f , g s : X ` Y Ñ σ Z f : X Ñ 2 Y ` Z g : Y Ñ σ V h : Z Ñ V r g , h s f : X Ñ σ V Definition (Guarded co-Cartesian category) A co-Cartesian category C equipped with distinguished subsets Hom σ p X , Y q Ď Hom p X , Y q of partially guarded morphisms for A , B P | C | , and any summand σ : Y 1 Ñ Y 1 ` Y 2 » Y satisfying the rules above is called guarded ( f : X Ñ σ Y means f P Hom σ p X , Y q ) 3/18

  9. (Abstractly) Guarded Symmetric Monoidal Categories 4/18

  10. ❼ ❼ Monads for Computations ❼ Monads formalize generalized functions f : X Ñ TY , like nondeterministic (with T “ P X ) or partial (with TX “ X ` 1) : : Moggi 1991, Notions of Computation and Monads ; Plotkin and Power 2002, Notions of Computation Determine Monads 5/18

  11. ❼ Monads for Computations ❼ Monads formalize generalized functions f : X Ñ TY , like nondeterministic (with T “ P X ) or partial (with TX “ X ` 1) : ❼ T is a type constructor, plus η : X Ñ TX (unit) and p f : X Ñ TY q ÞÑ p f ‹ : TX Ñ TY q (lifting), inducing the Klesili category of T : f ˛ g “ p f : Y Ñ TZ q ‹ p g : X Ñ TY q id “ η : X Ñ TX In Haskell’s point-full notation: do x Ð p ; f p x q “ f ‹ p p q : Moggi 1991, Notions of Computation and Monads ; Plotkin and Power 2002, Notions of Computation Determine Monads 5/18

  12. Monads for Computations ❼ Monads formalize generalized functions f : X Ñ TY , like nondeterministic (with T “ P X ) or partial (with TX “ X ` 1) : ❼ T is a type constructor, plus η : X Ñ TX (unit) and p f : X Ñ TY q ÞÑ p f ‹ : TX Ñ TY q (lifting), inducing the Klesili category of T : f ˛ g “ p f : Y Ñ TZ q ‹ p g : X Ñ TY q id “ η : X Ñ TX In Haskell’s point-full notation: do x Ð p ; f p x q “ f ‹ p p q ❼ Duality of operations and effects ; : e.g. for T “ P , toss “ t head , tail u p ` q “ do x Ð toss ; if p x “ head q then p else q . In this sense T Σ extends T with Σ-operations, e.g. for Σ “ A ˆ - -: a . p “ do p action a : 1 Ñ T Σ 1 q ; p : Moggi 1991, Notions of Computation and Monads ; Plotkin and Power 2002, Notions of Computation Determine Monads 5/18

  13. Abstract Guardedness on Monads Abstract guardedeness for a monad T is a relation between Kleisi morphisms f : X Ñ TY and summands σ : Y 1 Y satisfying f : X Ñ TY (trv) p T in 1 q f : X Ñ in 2 T p Y ` Z q f : X Ñ σ TZ g : Y Ñ σ TZ (sum) r f , g s : X ` Y Ñ σ TZ f : X Ñ in 2 T p Y ` Z q g : Y Ñ σ TV h : Z Ñ TV (cmp) r g , h s ‹ f : X Ñ σ TV where f : X Ñ σ TY , equivalently f P Hom σ p X , TY q , means that f and σ are in the relation 6/18

  14. Abstract Guardedness on Monads A monad is guarded Elgot if it supports partial iteration operator sending each f : X Ñ 2 T p Y ` X q to f : : X Ñ TY satisfying the fixpoint law f : “ r η, f : s ‹ f and other laws of iteration : Roughly: Semantics of while-loops Example: TX “ p X ˆ Nat ‹ q Y Nat ω , equivalently, TX is a final p X ` Nat ˆ - - q -coalgebra TX contains ❼ pairs p x , τ q of a result x P X and a finite trace τ P Nat ‹ , and ❼ infinite traces π P Nat ω : Bloom and ´ Esik 1993, Iteration theories: The equational logic of iterative processes 7/18

  15. A Monad of (In)Finite Traces ❼ The unit of TX “ p X ˆ Nat ‹ q Y Nat ω sends x to p x , x yq ❼ Given f : X Ñ TY , # ` τ 1 q if f p x q “ p y , τ 1 q , p y , τ ` f ‹ p x , τ q “ f ‹ p π q “ π. if f p x q “ π, ` π τ ` ❼ f : X Ñ inr p Y ` Z q ˆ Nat ‹ Y Nat ω if for every x P X , f p x q P Z ˆ Nat ‹ implies f p x q P Z ˆ Nat ` 8/18

  16. The Metalanguage

  17. Metalanguages for (Guarded) Iteration: Motivation ❼ Guardedness is a fundamental notion: Just like Moggi’s computational metalanguage is a metalanguage of abstract effects, the metalanguage for guarded iteration is a metalanguage of abstract guardedness ❼ The metalangauge for guarded iteration can be used as a ‘core programming language’ for effects associated with monads. The stock of examples is growing: various process semantic domains, hybrid monads, etc. 9/18

  18. The Main Idea Geron and Levy : observed that ❼ modelling iteration directly would amount to syntax like return inr . . . inr inl . . . which is like using De Bruijn indexes instead of variables ❼ they also proposed to use labels to index coproduct summands in f : X Ñ T p ř i X i q , so as to be able to point the branch in which to iterate Here, we assume labels = exceptions, for they can be uniformly used in three constructs exception raising exception handling iteration handleit x “ v in p raise e v handle x in p with q : Geron and Levy 2016, Iteration and labelled iteration 10/18

  19. Quick Example h a n d l e i t e = ‹ in handle u in ( print ( "think of a number" ) & r a i s e u ‹ ) with ( do y Ð random ( ) ; z Ð read ( ) ; i f ( y = z ) then r e t ‹ e l s e r a i s e e ‹ ) 11/18

  20. Syntax Types: A , B , . . . :: “ C | 0 | 1 | A ` B | A ˆ B p C P Base q Signatures: ❼ value signature Σ v of f : A Ñ B (e.g. ` : Nat ˆ Nat Ñ Nat ) ❼ effect signature Σ c of f : A Ñ B r C s (e.g. put : Nat Ñ 0 r 1 s ) Value and Computation Term Judgements: Γ $ v v : A and ∆ | Γ $ c p : A In ∆ types are tagged over t g , u u to indicate (un-)guardedness 12/18

  21. Some Derivation Rules e : E g in ∆ f : A Ñ 0 r 1 s P Σ c Γ $ v p : A Γ $ v q : E ∆ | Γ $ c f p p q & raise e q : D ∆ , e : E g | Γ $ c p : A ∆ 1 | Γ , e : E $ c q : A | ∆ | “ | ∆ 1 | ∆ | Γ $ c handle e in p with q : A e : E u in ∆ ∆ , e : E g | Γ , e : E $ c q : A Γ $ v q : E Γ $ v p : E ∆ | Γ $ c raise e q : D ∆ | Γ $ c handleit e “ p in q : A 13/18

  22. Generic Denotational Semantics

  23. Typing the Semantics Types: 0 “ ∅ , 1 “ 1 , A ` B “ A ` B , A ˆ B “ A ˆ B . Γ “ A 1 ˆ . . . ˆ A n for Γ “ p x 1 : A 1 , . . . , x n : A n q ∆ “ E 1 ` . . . ` E m for ∆ “ p e 1 : E α 1 1 , . . . , e m : E α m m q Signatures: � f � P Hom p A , B q f : A Ñ B P Σ v for � f � P Hom inr p A , T p B ` C qq for f : A Ñ B r C s P Σ c Terms: � Γ $ v v : A � P Hom p Γ , A q � ∆ | Γ $ c p : A � P Hom ! ` σ ∆ p Γ , T p A ` ∆ qq 14/18

  24. Operational Semantics and Adequacy

Recommend


More recommend