combining effects and
play

Combining Effects and Coeffects via Grading (slides) Marco Gaboardi - PowerPoint PPT Presentation

Combining Effects and Coeffects via Grading (slides) Marco Gaboardi Shin-ya Katsumata Dominic Orchard SUNY Buffalo, USA Kyoto University, Japan University of Kent, UK Flavien Breuvart Tarmo Uustalu INRA Sophia Antipolis, France Institute


  1. Combining Effects and Coeffects via Grading (slides) Marco Gaboardi Shin-ya Katsumata Dominic Orchard SUNY Buffalo, USA Kyoto University, Japan University of Kent, UK Flavien Breuvart Tarmo Uustalu INRA Sophia Antipolis, France Institute of Cybernetics at TUT, Estonia ICFP 2016, Nara, Japan - September 21st

  2. What are coeffects? Computations make changes to the context (effects) and make demands from the context (coeffects). • Per-variable coeffect dependency properties: ‣ Live-variable analysis (live/dead) ‣ Information flow, e.g., security levels (High/Low) ‣ Bounded Linear Logic (how much variable reuse? resource analysis) ‣ Deconstructors (strictness analysis) ‣ Probabilities and schedules Whole-context coeffect dependencies ( not in this paper ) • ‣ Additional hardware resources ‣ Library versions ‣ Type class instances 1/16

  3. Coeffect analysis and meta languages • Type-and-coeffect system ➡ whole-context analysis [Petricek et al. ’13] Γ | r ` e : τ ➡ per-variable analysis [Petricek et al. ’14, Ghica & Smith ’14] x : A · r, . . . , y : B · s ` e : τ • Coeffect meta-language [Brunel et al. ’14] ➡ indexed type constructor, generalises linear exponential Γ , x : ! r A ` e : ! s A • Semiring structure on coeffect information • Semantics via graded comonads 2/16

  4. This paper: effect and coeffect interactions ➡ Consider two examples: ‣ Security levels masking non-determinism ‣ Exceptions change linear reuse bounds ➡ Core calculus ‣ linear-lambda calculus with effect and coeffect types Γ ` t : T e A Γ , x : ⇤ r A ` t : B ‣ parametric in effect, coeffect algebra ➡ Graded semantics: graded monads, graded comonads, graded distributive laws (new here) 3/16

  5. Graded semantics Core calculus Interaction example

  6. Graded semantics Core calculus Interaction example

  7. A → TB B → TC comp id A → TC A → TA monads 4/16

  8. Graded slogan : B → T f C A → T e B comp match the structure of id A → T e • f C A → T 1 A computation with structure graded monad [Katsumata ’14] in the indices with monoid ( E, • , 1) ⇤ r A → B ⇤ s B → C comp id ⇤ 1 A → A ⇤ r ∗ s A → C with monoid ( R, ∗ , 1) graded comonad [coeffect papers ] 6/16

  9. Graded semantics Core calculus Interaction example

  10. Graded semantics Core calculus Interaction example

  11. Core calculus i. Graded monadic meta language for effects ii. Graded comonadic meta language for coeffects iii. Linear lambda calculus (substructural via coeffects) iv. Graded distributed law for interaction 7/16

  12. 1. Graded monadic m eta language for effects Pre-ordered monoid of effect information E = ( E , • , 1 , ≤ ) Γ ` t 1 : T e A ∆ , x : A ` t 2 : T f B Γ ` t : A unit letT Γ ` h t i : T 1 A Γ + ∆ ` let h x i = t 1 in t 2 : T e • f B e.g., exceptions, with simple analysis E = { > , ? } 1 = > = definite exception ⊥ ? ^ ? = ? • = ∧ = may succeed > ? ^ > = ? > ^ ? = ? > ^ > = > 8/16

  13. 2. Graded comonad meta language for coeffects Pre-ordered semiring of coeffect information C = ( C , ∗ , 1 , + , 0 , ≤ ) ⇤ Γ ` t : B Γ , x : A ` t : B der pr r ⇤ ⇤ Γ ` [ t ] : ⇤ r B Γ , x : ⇤ 1 A ` t : B let ⇤ Γ ` t 1 : ⇤ r A ∆ , x : ⇤ r A ` t 2 : B Γ + ∆ ` let [ x ] = t 1 in t 2 : B e.g. Bounded Linear Logic (Girard et al.) C = ( N , ∗ , 1 , + , 0 , ≤ ) x : [ int ] 1 , y : [ int ] 2 ` x + y + y : int 2 ` 1 pr pr x : [ int ] 2 , y : [ int ] 4 ` [ x + y + y ] : ⇤ 2 int 9/16

  14. 3. Linear lambda calculus ∆ ` t 0 : A Γ , x : A ` t : B Γ ` t : A ! B ax abs app Γ + ∆ ` t t 0 : B x : A ` x : A Γ ` λ x.t : A ! B Coeffect + for contraction ( let ☐ ), ( letT ), ( app ) ( x : A, Γ ) + ( x : A, ∆ ) is ill-formed ( x : ⇤ r A, Γ ) + ( x : ⇤ s A, ∆ ) = x : ⇤ r + s A, ( Γ + ∆ ) Coeffect 0 for weakening ( sub ) Γ 0 < : Γ Γ ` t : A A < : B sub Γ 0 , ⇤ 0 ∆ ` t : B 10/16

  15. Graded semantics Core calculus Interaction example

  16. Graded semantics Core calculus Interaction example

  17. BLL / exception composition (definite exception) Γ ` t 1 : T ⊥ A ∆ , x : ⇤ r A ` t 2 : B ∆ , x : ⇤ r A ` t 2 : B der* ⇤ 1 Γ ` t 1 : T ⊥ A unit ∆ , x : ⇤ r A ` h t 2 i : T 1 B pr pr ⇤ r Γ ` [ t 1 ] : ⇤ r T ⊥ A ⇤ ∆ , x 0 : T ? ⇤ r A ` . . . : T ? B Goal: an exception “cancels out” resource requirements i.e. (above) r = 1 11/16

  18. BLL / exception composition (definite exception) Γ ` t 1 : T ⊥ A ∆ , x : ⇤ r A ` t 2 : B ∆ , x : ⇤ r A ` t 2 : B der* ⇤ 1 Γ ` t 1 : T ⊥ A unit ∆ , x : ⇤ r A ` h t 2 i : T 1 B pr pr ⇤ 1 Γ ` [ t 1 ] : ⇤ 1 T ⊥ A ⇤ ∆ , x 0 : T ? ⇤ r A ` . . . : T ? B ≠ Goal: an exception “cancels out” resource requirements i.e. (above) r = 1 🔕 sequence :: Monad m => [m a] → m [a] Notion of a distributive law of comonad over monad provides: dist : ⇤ T A → T ⇤ A Indexed distributive law? No effect and coeffect interaction dist r,e,A : ⇤ r T e A → T e ⇤ r A 11/16

  19. Indexed vs. graded distributive law Indexed: dist r,e,A : ⇤ r T e A → T e ⇤ r A Graded slogan: algebraic structure on indices matching shape of computation distributive law on monoids: “matched pair” (Zappa-Szep product) h κ , ι i : R ⇥ E ! E ⇥ R ι : R × E → R κ : R × E → E ι ( r, 1) = r ι ( r, e • f ) = ι ( ι ( r, e ) , f ) ι (1 , e ) = 1 ι ( r ∗ s, e ) = ι ( r, κ ( s, e )) ∗ ι ( s, e ) κ (1 , e ) = e κ ( r ∗ s, e ) = κ ( r, κ ( s, e )) κ ( r, 1) = 1 κ ( r, e • f ) = κ ( r, e ) • κ ( ι ( r, e ) , f ) Graded: dist r,e,A : ⇤ ι ( r,e ) T e A → T κ ( r,e ) ⇤ r A Primitive in our core calculus 12/16

  20. BLL / exception composition Γ ` t 1 : T ⊥ A ∆ , x : ⇤ r A ` t 2 : B ∆ , x : ⇤ r A ` t 2 : B der* ⇤ 1 Γ ` t 1 : T ⊥ A unit ∆ , x : ⇤ r A ` h t 2 i : T 1 B pr pr ⇤ 1 Γ ` [ t 1 ] : ⇤ 1 T ⊥ A ⇤ ∆ , x 0 : T ? ⇤ r A ` . . . : T ? B Goal: an exception “cancels out” resource requirements •Matched pair dist r,e,A : ⇤ ι ( r,e ) T e A → T κ ( r,e ) ⇤ r A κ ( r, e ) = e 13/16

  21. BLL / exception composition Γ ` t 1 : T ⊥ A ∆ , x : ⇤ r A ` t 2 : B ∆ , x : ⇤ r A ` t 2 : B der* ⇤ 1 Γ ` t 1 : T ⊥ A unit ∆ , x : ⇤ r A ` h t 2 i : T 1 B pr pr ⇤ 1 Γ ` [ t 1 ] : ⇤ 1 T ⊥ A ⇤ ∆ , x 0 : T ? ⇤ r A ` . . . : T ? B •Matched pair dist r,e,A : ⇤ ι ( r,e ) T e A → T e ⇤ r A κ ( r, e ) = e ι ( r, ⊥ ) = 1 Goal: an exception “cancels out” resource requirements 13/16

  22. BLL / exception composition Γ ` t 1 : T ⊥ A ∆ , x : ⇤ r A ` t 2 : B ∆ , x : ⇤ r A ` t 2 : B der* ⇤ 1 Γ ` t 1 : T ⊥ A unit ∆ , x : ⇤ r A ` h t 2 i : T 1 B pr pr ⇤ 1 Γ ` [ t 1 ] : ⇤ 1 T ⊥ A ⇤ ∆ , x 0 : T ? ⇤ r A ` . . . : T ? B ⇤ 1 Γ ` dist [ t 1 ] : T ⊥ ⇤ r A ∆ + ⇤ 1 Γ ` let x 0 = dist [ t 1 ] in . . . : T ? A •Matched pair dist r, ⊥ ,A : ⇤ 1 T ⊥ A → T ⊥ ⇤ r A κ ( r, e ) = e dist r, > ,A : ⇤ r T > A → T > ⇤ r A ι ( r, ⊥ ) = 1 ι ( r, > ) = r ✔ Goal: an exception “cancels out” resource requirements 13/16

  23. 4. Graded distributive law design space “T ☐ ” vs “ ☐ T” T ⇤ A → ⇤ T A ⇤ T A → T ⇤ A “forward” ( L ) vs “backward” ( R ) T e ⇤ ... A → ⇤ ... T κ ( e,r ) A T ... ⇤ r A → ⇤ ι ( r,e ) T ... A T κ ( e,r ) ⇤ ... A → ⇤ ... T e A T ... ⇤ ι ( r,e ) A → ⇤ r T ... A T over ⇤ ( T ⇤ ) ⇤ over T ( ⇤ T ) φ F φ G φ F φ G φ r,e r,e r,e r,e T e T κ ( r,e ) T e T κ ( r,e ) ⇤ r ⇤ ι ( r,e ) ⇤ r ⇤ ι ( r,e ) ll → → T κ ( r,e ) ⇤ ι ( r,e ) ⇤ r T e ⇤ ι ( r,e ) T κ ( r,e ) T e ⇤ r rr → → T e ⇤ ι ( r,e ) ⇤ r T κ ( r,e ) ⇤ ι ( r,e ) T e T κ ( r,e ) ⇤ r lr → → T κ ( r,e ) T e T κ ( r,e ) T e ⇤ r ⇤ ι ( r,e ) ⇤ r ⇤ ι ( r,e ) rl → → ` dist φ : F φ r,e A ! G φ r,e A 14/16

  24. Categorical semantics • Graded strong monad (Katsumata 2014) • Graded monoidal comonad (Petricek et al. 2013, Brunel et al. 2014, Petricek et al. 2014, Ghica&Smith et al. 2014) • Family of matched-pair graded distributive law (new) • Soundness theorem 15/16

  25. Concluding remarks • Foundation for considering effect-coeffect interaction • Further possibilities? • Exceptions interacting with security levels (e.g., content of a high security exception not observable to lower security observer) • Non-determinism with probabilistic variables • Graded distributive laws useful in other contexts sequence :: [m a] → m [a] sequence :: [m e a] n → m e n [a] n Thank you. 16/16

  26. Extras

  27. Graded distributive law f g D r A → T e B D s B → T f C − − → − − → f † g ∗ σ s,e,A σ s,e,A D r ∗ ι ( s,e ) A → D ι ( s,e ) T e B → D ι ( s,e ) T e B → T κ ( s,e ) D s B → T κ ( s,e ) D s B → T κ ( s,e ) • f C − − − − − − − − − − − backward propagation of coeffects forward propagation of effects distributive law on monoids: “matched pair” (Zappa-Szep product) (monoid on E × R ) h κ , ι i : R ⇥ E ! E ⇥ R ι : R × E → R κ : R × E → E ι ( r, 1) = r ι ( r, e • f ) = ι ( ι ( r, e ) , f ) ι (1 , e ) = 1 ι ( r ∗ s, e ) = ι ( r, κ ( s, e )) ∗ ι ( s, e ) κ (1 , e ) = e κ ( r ∗ s, e ) = κ ( r, κ ( s, e )) κ ( r, 1) = 1 κ ( r, e • f ) = κ ( r, e ) • κ ( ι ( r, e ) , f ) 17/16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend