Strict and Lazy Semantics for Effects Layering Monads




































- Slides: 36
Strict and Lazy Semantics for Effects Layering Monads and Comonads Andrew K. Hirsch and Ross Tate 1
Reduce 1 st Reduce Done reducing; Discard unused 2
Unused Throws Exception 3
Throws an Might not produce exception its outputs Might not consume its inputs Producer Choice (of Quantity) Consumer Choice (of Quantity) Pure = Linear 4
Producer Choice There was a problem, stop everything! Consumer Choice 5
Producer Choice We don’t need that, don’t bother evaluating it Consumer Choice 6
Eff ect o M s d a n o m o C s s s ne s d s s e n i z a L & t c tri S 7
How do I use these together? m o C a on s d a n o M 8
Effectful Language Non-Linear Language with Exceptions Example language with strict and lazy semantics Comp – Language of Computations Pure Language Linear Language without Exceptions Process calculus with linear session types Proc – Language of Processes 9
exn And this program never runs Linear If this Proc throws an Program exception exn Bind propagates that exception So this bind throws an exception Capturing Exceptions in a Monad 10
Connections drop to logic in paper And this From linear does not logic need to run A comonad If this is Cobind propagates So this cobind dropped that drop should be dropped Capturing Drops in a Comonad 11
Comp Proc Generalizes Maybe From Linear Logic exn drop exn, drop 12
How do I use these together? m o C a on s d a n o M 13
Comp Proc Generalizes Maybe From Linear Logic exn drop exn, drop straightforward 14
exn, drop exn, drop 15
exn, drop Distributive Law cobind exn, drop 16
With a distributive law m o C a on s d How do I use these together? s d a n o M 17
exn, drop cobind Distributive Law exn, drop bind 18
With a distributive law m o C a on s d How do I use these together? s d a n o M 19
Producer Choice Consumer Choice 20
exn, drop So this program never runs If this program throws an exception Bind will propagate that exception exn, drop bind The Monad-Prioritizing Layering 21
Comp Proc Generalizes Maybe From Linear Logic exn drop exn, drop Monad-Prioritizing 22
Producer Choice Consumer Choice 23
exn, drop So this program never runs exn, drop cobind Cobind will propagate that drop If this program drops its input The Comonad-Prioritizing Layering 24
Comp Proc Generalizes Maybe From Linear Logic exn drop exn, drop Comonad-Prioritizing 25
Programs Monad. Prioritizing Proc strict Monad. Prioritizing Comp Values 26
Programs Comonad. Prioritizing Proc lazy Comonad. Prioritizing Comp Values 27
By choosing a layering m o C a on s d How do I use these together? s d a n o M 28
Eff ect o M s d a n o m o C s s s ne s d s s e n i z a L & t c tri S 29
Producer Effect Generalizing Layering 30
Producer Effect Consumer Effect Comonad. Prioritizing “Lazy” Monad. Prioritizing “Strict” Generalizing Layering 31
Choice is between a “strict” and a “lazy” semantics for effects. If there is not a distributive law: 1. Monad-Prioritizing Layering 2. Comonad-Prioritizing Layering 32
Theorem: All three semantics are the same. If there is a distributive law: 1. Monad-Prioritizing Layering 2. Comonad-Prioritizing Layering 3. Distributive-Law Based Semantics 33
Theorem: If there is a distributive law, then all three semantics are the same. Reduce 1 st Corollary: There is no distributive law of ! over ? Done reducing; Reduce 1 st Discard unused 34
In the paper • Connections to logic (linear and classical) • A formalization of doubly-effectful languages • Categorical Formalization • Theorem Details • mostly in the tech report 35
Thanks 36