×

Not by equations alone. Reasoning with extensible effects. (English) Zbl 1522.68124

Summary: The challenge of reasoning about programs with (multiple) effects such as mutation, jumps, or IO dates back to the inception of program semantics in the works of Strachey and Landin. Using monads to represent individual effects and the associated equational laws to reason about them proved exceptionally effective. Even then it is not always clear what laws are to be associated with a monad – for a good reason, as we show for non-determinism. Combining expressions using different effects brings challenges not just for monads, which do not compose, but also for equational reasoning: the interaction of effects may invalidate their individual laws, as well as induce emerging properties that are not apparent in the semantics of individual effects. Overall, the problems are judging the adequacy of a law; determining if or when a law continues to hold upon addition of new effects; and obtaining and easily verifying emergent laws.
We present a solution relying on the framework of (algebraic, extensible) effects, which already proved itself for writing programs with multiple effects. Equipped with a fairly conventional denotational semantics, this framework turns useful, as we demonstrate, also for reasoning about and optimizing programs with multiple interacting effects. Unlike the conventional approach, equational laws are not imposed on programs/effect handlers, but induced from them: our starting point hence is a program (model), whose denotational semantics, besides being used directly, suggests and justifies equational laws and clarifies side conditions. The main technical result is the introduction of the notion of equivalence modulo handlers (“modulo observation”) or a particular combination of handlers – and proving it to be a congruence. It is hence usable for reasoning in any context, not just evaluation contexts – provided particular conditions are met.
Concretely, we describe several realistic handlers for non-determinism and elucidate their laws (some of which hold in the presence of any other effect). We demonstrate appropriate equational laws of non-determinism in the presence of global state, which have been a challenge to state and prove before.

MSC:

68N18 Functional programming and lambda calculus
68N30 Mathematical aspects of software engineering (specification, verification, metrics, requirements, etc.)
68Q55 Semantics in the theory of computing
Full Text: DOI

References:

[1] Affeldt, Reynald & Nowak, David. (2018). Experimenting with monadic equational reasoning in Coq. The 35th Conference of the Japan Society for Software Science and Technology.
[2] Armoni, Michal & Ben-Ari, Mordechai. (2009). The concept of nondeterminism: its development and implications for teaching. Sigcse bulletin, 41(2), 141-160.
[3] Bauer, Andrej & Pretnar, Matija. (2014). An effect system for algebraic effects and handlers. Logical methods in computer science, 1(4). · Zbl 1448.68203
[4] Bauer, Andrej & Pretnar, Matija. (2015). Programming with algebraic effects and handlers. Journal of logical and algebraic methods in programming, 84(1), 108-123. · Zbl 1304.68025
[5] Brady, Edwin. (2013). Programming and reasoning with algebraic effects and dependent types. Pages 133-144 of: ICFP ’13. ACM Press. · Zbl 1323.68097
[6] Cartwright, Robert & Felleisen, Matthias. (1994). Extensible denotational language specifications. Pages 244-272 of:Hagiya, Masami & Mitchell, John C. (eds), Theor. Aspects of Comp. Soft. LNCS, no. 789. Springer. · Zbl 0942.68544
[7] Chen, Yu-Fang, Hong, Chih-Duo, Lengál, Ondřej, Mu, Shin-Cheng, Sinha, Nishant & Wang, Bow-Yaw. (2017). An executable sequential specification for Spark aggregation. International Conference on Networked Systems. Springer-Verlag.
[8] Fischer, Sebastian, Kiselyov, Oleg & Shan, Chung-Chieh. (2011). Purely functional lazy nondeterministic programming. Journal of functional programming, 21, 413-465. · Zbl 1262.68032
[9] Forster, Yannick, Kammar, Ohad, Lindley, Sam & Pretnar, Matija. (2019). On the expressive power of user-defined effects: Effect handlers, monadic reflection, delimited control. J. funct. program, 29, e15.
[10] Gibbons, Jeremy & Hinze, Ralf. (2011). Just do it: Simple monadic equational reasoning. Pages 2-14 of: ICFP ’11. ACM Press. · Zbl 1323.68207
[11] Harel, David & Pratt, Vaughan R. 1978 (Jan.). Nondeterminism in logics of programs (preliminary report). Pages 203-213 of: Conference Record of the Fifth Annual ACM Symposium on Principles of Programming Languages.
[12] Hinze, Ralf. (2000). Deriving backtracking monad transformers. Pages 186-197 of: ICFP ’00. ACM Press. · Zbl 1321.68195
[13] Hutton, Graham & Fulger, Diana. (2007). Reasoning about effects: seeing the wood through the trees. Symposium on Trends in Functional Programming.
[14] Hyland, Martin, Plotkin, Gordon & Power, John. (2006). Combining effects: Sum and tensor. Theoretical computer science, 357(1-3), 70-99. · Zbl 1096.68088
[15] Johann, Patricia, Simpson, Alex & Voigtl’Ander, Janis. (2010). A generic operational metatheory for algebraic effects. Pages 209-218 of: LICS. IEEE Press.
[16] Kiselyov, Oleg. 2017 (3 Sept.). Higher-order programming is an effect. HOPE 2017 at ICFP 2017.
[17] Kiselyov, Oleg & Ishii, Hiromi. (2015). Freer monads, more extensible effects. Pages 94-105 of: Proceedings of the 8th ACM SIGPLAN symposium on Haskell, Vancouver, BC, Canada, September 3-4, 2015. ACM.
[18] Kiselyov, Oleg & Sivaramakrishnan, Kc. (2018). Eff directly in OCaml. Electronic proceedings in theoretical computer science, 285, 23-58.
[19] Kiselyov, Oleg, Sabry, Amr & Swords, Cameron. (2013). Extensible effects: an alternative to monad transformers. Pages 59-70 of: Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Boston, MA, USA, September 23-24, 2013. ACM.
[20] Leijen, Daan. (2017). Type directed compilation of row-typed algebraic effects. Pages 486-499 of: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. POPL 2017. New York, NY, USA: ACM. · Zbl 1380.68097
[21] Moggi, Eugenio. (1989). An abstract view of programming languages. Tech. rept. ECS-LFCS-90-113. Edinburgh Univ.
[22] Mosses, Peter D. (1990). Denotational semantics. Chap. 11, pages 577-631 of:Van Leewen, J. (ed), Handbook of Theoretical Computer Science, vol. B: Formal Models and Semantics. New York, NY: The MIT Press. · Zbl 0900.68295
[23] Mu, Shin-Cheng. (2019a). Calculating a backtracking algorithm: an exercise in monadic program derivation. Tech. rept. TR-IIS-19-003. Institute of Information Science, Academia Sinica.
[24] Mu, Shin-Cheng. (2019b). Equational reasoning for non-determinism monad: the case of Spark aggregation. Tech. rept. TR-IIS-19-002. Institute of Information Science, Academia Sinica.
[25] Pitts, Andrew M. (1996). Relational properties of domains. Information and computation, 127(2), 66-90. · Zbl 0868.68037
[26] Plotkin, Gordon & Power, John. (2003). Algebraic operations and generic effects. Applied categorical structures, 11(1), 69-94. · Zbl 1023.18006
[27] Plotkin, Gordon & Pretnar, Matija. (2009). Handlers of algebraic effects. Pages 80-94 of:Castagna, Giuseppe (ed), Programming Languages and Systems. Lecture Notes in Computer Science, vol. 5502. Springer. · Zbl 1234.68059
[28] Pretnar, Matija. (2010). The logic and handling of algebraic effects. Ph.D. thesis, The University of Edinburgh. · Zbl 1351.68079
[29] Rabin, Michael O. & Scott, Dana. (1959). Finite automata and their decision problems. IBM journal of research and development, 3, 114-125. · Zbl 1461.68105
[30] Reynolds, John C. (1981). The essence of Algol. Pages 345-372 of:De Bakker, Jacobus Willem & Van Vliet, J. C. (eds), Algorithmic Languages. Amsterdam: North-Holland.
[31] Thompson, Ken. (1968). Programming techniques: Regular expression search algorithm. Commun. acm, 11(6), 419-422. · Zbl 0164.46205
[32] Winskel, Glynn. (1993). Formal semantics of programming languages. MIT Press. · Zbl 0919.68082
[33] Wu, Nicolas, Schrijvers, Tom & Hinze, Ralf. (2014). Effect handlers in scope. Pages 1-12 of: Proceedings of the 7th ACM SIGPLAN symposium on Haskell, Gothenburg, Sweden, September 4-5, 2014. ACM.
[34] Zaharia, Matei, Chowdhury, Mosharaf, Franklin, Michael J., Shenker, Scott & Stoica, Ion. (2010). Spark: Cluster computing with working sets. Proceedings of the 2Nd USENIX Conference on Hot Topics in Cloud Computing. HotCloud’10. Berkeley, CA, USA: USENIX Association.
This reference list is based on information provided by the publisher or from digital mathematics libraries. Its items are heuristically matched to zbMATH identifiers and may contain data conversion errors. In some cases that data have been complemented/enhanced by data from zbMATH Open. This attempts to reflect the references listed in the original paper as accurately as possible without claiming completeness or a perfect matching.