Hostname: page-component-8448b6f56d-tj2md Total loading time: 0 Render date: 2024-04-23T21:02:46.868Z Has data issue: false hasContentIssue false

Not by equations alone: Reasoning with extensible effects

Published online by Cambridge University Press:  27 January 2021

OLEG KISELYOV
Affiliation:
Graduate School of Information Sciences, Tohoku University, Sendai, Miyagi, Japan (e-mail: oleg@okmij.org)
SHIN-CHENG MU
Affiliation:
Institute of Information Science, Academia Sinica, Taipei, Taiwan (e-mail: scm@iis.sinica.edu.tw)
AMR SABRY
Affiliation:
Department of Computer Science, Indiana University, Bloomington, IN, USA (e-mail: sabry@indiana.edu)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

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.

Type
Research Article
Copyright
© The Author(s), 2021. Published by Cambridge University Press

References

Affeldt, Reynald & Nowak, David. (2018). Experimenting with monadic equational reasoning in Coq. The 35th Conference of the Japan Society for Software Science and Technology.Google Scholar
Armoni, Michal & Ben-Ari, Mordechai. (2009). The concept of nondeterminism: its development and implications for teaching. Sigcse bulletin, 41(2), 141160.CrossRefGoogle Scholar
Bauer, Andrej & Pretnar, Matija. (2014). An effect system for algebraic effects and handlers. Logical methods in computer science, 1(4).Google Scholar
Bauer, Andrej & Pretnar, Matija. (2015). Programming with algebraic effects and handlers. Journal of logical and algebraic methods in programming, 84(1), 108123.CrossRefGoogle Scholar
Brady, Edwin. (2013). Programming and reasoning with algebraic effects and dependent types. Pages 133–144 of: ICFP ’13. ACM Press.Google Scholar
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.Google Scholar
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.Google Scholar
Fischer, Sebastian, Kiselyov, Oleg & Shan, Chung-Chieh. (2011). Purely functional lazy nondeterministic programming. Journal of functional programming, 21, 413465.CrossRefGoogle Scholar
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.CrossRefGoogle Scholar
Gibbons, Jeremy & Hinze, Ralf. (2011). Just do it: Simple monadic equational reasoning. Pages 2–14 of: ICFP ’11. ACM Press.Google Scholar
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.CrossRefGoogle Scholar
Hinze, Ralf. (2000). Deriving backtracking monad transformers. Pages 186–197 of: ICFP ’00. ACM Press.Google Scholar
Hutton, Graham & Fulger, Diana. (2007). Reasoning about effects: seeing the wood through the trees. Symposium on Trends in Functional Programming.Google Scholar
Hyland, Martin, Plotkin, Gordon & Power, John. (2006). Combining effects: Sum and tensor. Theoretical computer science, 357(1–3), 7099.CrossRefGoogle Scholar
Johann, Patricia, Simpson, Alex & Voigtl’ander, Janis. (2010). A generic operational metatheory for algebraic effects. Pages 209–218 of: LICS. IEEE Press.Google Scholar
Kiselyov, Oleg. 2017 (3 Sept.). Higher-order programming is an effect. HOPE 2017 at ICFP 2017.Google Scholar
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.Google Scholar
Kiselyov, Oleg & Sivaramakrishnan, KC. (2018). Eff directly in OCaml. Electronic proceedings in theoretical computer science, 285, 2358.CrossRefGoogle Scholar
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.Google Scholar
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.Google Scholar
Moggi, Eugenio. (1989). An abstract view of programming languages. Tech. rept. ECS-LFCS-90-113. Edinburgh Univ.Google Scholar
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.Google Scholar
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.Google Scholar
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.Google Scholar
Pitts, Andrew M. (1996). Relational properties of domains. Information and computation, 127(2), 6690.CrossRefGoogle Scholar
Plotkin, Gordon & Power, John. (2003). Algebraic operations and generic effects. Applied categorical structures, 11(1), 6994.CrossRefGoogle Scholar
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.Google Scholar
Pretnar, Matija. (2010). The logic and handling of algebraic effects. Ph.D. thesis, The University of Edinburgh.Google Scholar
Rabin, Michael O. & Scott, Dana. (1959). Finite automata and their decision problems. IBM journal of research and development, 3, 114125.CrossRefGoogle Scholar
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.Google Scholar
Thompson, Ken. (1968). Programming techniques: Regular expression search algorithm. Commun. acm, 11(6), 419422.CrossRefGoogle Scholar
Winskel, Glynn. (1993). Formal semantics of programming languages. MIT Press.CrossRefGoogle Scholar
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.Google Scholar
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.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.