Abstract
Monadic computations built by interpreting, or handling, operations of a free monad are a compelling formalism for modeling language semantics and defining the behaviors of effectful systems. The resulting layered semantics offer the promise of modular reasoning principles based on the equational theory of the underlying monads. However, there are a number of obstacles to using such layered interpreters in practice. With more layers comes more boilerplate and glue code needed to define the monads and interpreters involved. That overhead is compounded by the need to define and justify the relational reasoning principles that characterize the equivalences at each layer. This paper addresses these problems by significantly extending the capabilities of the Coq interaction trees (ITrees) library, which supports layered monadic interpreters. We characterize a rich class of interpretable monads---obtained by applying monad transformers to ITrees---and show how to generically lift interpreters through them. We also introduce a corresponding framework for relational reasoning about "equivalence of monads up to a relation R". This collection of typeclasses, instances, new reasoning principles, and tactics greatly generalizes the existing theory of the ITree library, eliminating large amounts of unwieldy boilerplate code and dramatically simplifying proofs.
- Martín Abadi, Anindya Banerjee, Nevin Heintze, and Jon G. Riecke. 1999. A Core Calculus of Dependency. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’99). Association for Computing Machinery, New York, NY, USA. 147–160. isbn:1581130953 https://doi.org/10.1145/292540.292555
Google Scholar
Digital Library
- Danel Ahman, Cătălin Hriţcu, Kenji Maillard, Guido Martínez, Gordon Plotkin, Jonathan Protzenko, Aseem Rastogi, and Nikhil Swamy. 2017. Dijkstra Monads for Free. SIGPLAN Not., 52, 1 (2017), jan, 515–529. issn:0362-1340 https://doi.org/10.1145/3093333.3009878
Google Scholar
Digital Library
- Amal Jamil Ahmed. 2004. Semantics of Types for Mutable State. Ph. D. Dissertation. USA. AAI3136691
Google Scholar
- Heinrich Apfelmus. 2010. The Operational Monad Tutorial. The Monad.Reader, Issue 15 (2010).
Google Scholar
- Andrew W. Appel and David McAllester. 2001. An Indexed Model of Recursive Types for Foundational Proof-Carrying Code. ACM Trans. Program. Lang. Syst., 23, 5 (2001), sep, 657–683. issn:0164-0925 https://doi.org/10.1145/504709.504712
Google Scholar
Digital Library
- Andrej Bauer and Matija Pretnar. 2013. An Effect System for Algebraic Effects and Handlers. Logical Methods in Computer Science, 10, https://doi.org/10.1007/978-3-642-40206-7_1
Google Scholar
Cross Ref
- Andrej Bauer and Matija Pretnar. 2015. Programming with algebraic effects and handlers. Journal of Logical and Algebraic Methods in Programming, 84, 1 (2015), 108–123. issn:2352-2208 https://doi.org/10.1016/j.jlamp.2014.02.001 Special Issue: The 23rd Nordic Workshop on Programming Theory (NWPT 2011) Special Issue: Domains X, International workshop on Domain Theory and applications, Swansea, 5-7 September, 2011
Google Scholar
Cross Ref
- Nick Benton. 2004. Simple Relational Correctness Proofs for Static Analyses and Program Transformations. SIGPLAN Not., 39, 1 (2004), jan, 14–25. issn:0362-1340 https://doi.org/10.1145/982962.964003
Google Scholar
Digital Library
- Nick Benton, Andrew Kennedy, Lennart Beringer, and Martin Hofmann. 2009. Relational Semantics for Effect-Based Program Transformations: Higher-Order Store. In Proceedings of the 11th ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP ’09). Association for Computing Machinery, New York, NY, USA. 301–312. isbn:9781605585680 https://doi.org/10.1145/1599410.1599447
Google Scholar
Digital Library
- Stephen L. Bloom and Zoltán Ésik. 1993. Iteration Theories - The Equational Logic of Iterative Processes. Springer. isbn:978-3-642-78036-3 https://doi.org/10.1007/978-3-642-78034-9
Google Scholar
Cross Ref
- Venanzio Capretta. 2005. General Recursion via Coinductive Types. Logical Methods in Computer Science, Volume 1, Issue 2 (2005), July, https://doi.org/10.2168/LMCS-1(2:1)2005
Google Scholar
Cross Ref
- Derek Dreyer, Amal Ahmed, and Lars Birkedal. 2009. Logical Step-Indexed Logical Relations. In Proceedings of the 2009 24th Annual IEEE Symposium on Logic In Computer Science (LICS ’09). IEEE Computer Society, USA. 71–80. isbn:9780769537467 https://doi.org/10.1109/LICS.2009.34
Google Scholar
Digital Library
- Jean Goubault-Larrecq, Slawomir Lasota, and David Nowak. 2008. Logical relations for monadic types. Math. Struct. Comput. Sci., 18, 6 (2008), 1169–1217. https://doi.org/10.1017/S0960129508007172
Google Scholar
Digital Library
- Peter Hancock and Anton Setzer. 2000. Interactive Programs in Dependent Type Theory. In Proceedings of the 14th Annual Conference of the EACSL on Computer Science Logic. Springer-Verlag, Berlin, Heidelberg. 317–331. isbn:3540678956 https://doi.org/10.1007/3-540-44622-2_21
Google Scholar
Cross Ref
- Claudio Hermida, Uday S. Reddy, Edmund P. Robinson, and Alessio Santamaria. 2020. Bisimulation as a Logical Relation. CoRR, abs/2003.13542 (2020), arXiv:2003.13542. arxiv:2003.13542
Google Scholar
- Chung-Kil Hur, Derek Dreyer, Georg Neis, and Viktor Vafeiadis. 2012. The marriage of bisimulations and Kripke logical relations. In Proceedings of the 39th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2012, Philadelphia, Pennsylvania, USA, January 22-28, 2012, John Field and Michael Hicks (Eds.). ACM, 59–72. https://doi.org/10.1145/2103656.2103666
Google Scholar
Digital Library
- Martin Hyland, Gordon Plotkin, and John Power. 2006. Combining effects: Sum and tensor. Theoretical Computer Science, 357, 1 (2006), 70 – 99. issn:0304-3975 https://doi.org/10.1016/j.tcs.2006.03.013 Clifford Lectures and the Mathematical Foundations of Programming Semantics
Google Scholar
Digital Library
- Patricia Johann and Neil Ghani. 2009. A principled approach to programming with nested types in Haskell. High. Order Symb. Comput., 22, 2 (2009), 155–189. https://doi.org/10.1007/s10990-009-9047-7
Google Scholar
Digital Library
- Ralf Jung, David Swasey, Filip Sieczkowski, Kasper Svendsen, Aaron Turon, Lars Birkedal, and Derek Dreyer. 2015. Iris: Monoids and Invariants as an Orthogonal Basis for Concurrent Reasoning. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015, Sriram K. Rajamani and David Walker (Eds.). ACM, 637–650. https://doi.org/10.1145/2676726.2676980
Google Scholar
Digital Library
- Oleg Kiselyov and Hiromi Ishii. 2015. Freer Monads, More Extensible Effects. SIGPLAN Not., 50, 12 (2015), aug, 94–105. issn:0362-1340 https://doi.org/10.1145/2887747.2804319
Google Scholar
Digital Library
- Oleg Kiselyov, Amr Sabry, and Cameron Swords. 2013. Extensible effects: an alternative to monad transformers. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Boston, MA, USA, September 23-24, 2013, Chung-chieh Shan (Ed.). ACM, 59–70. https://doi.org/10.1145/2503778.2503791
Google Scholar
Digital Library
- Vasileios Koutavas and Mitchell Wand. 2006. Small bisimulations for reasoning about higher-order imperative programs. In Proceedings of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2006, Charleston, South Carolina, USA, January 11-13, 2006, J. Gregory Morrisett and Simon L. Peyton Jones (Eds.). ACM, 141–152. https://doi.org/10.1145/1111037.1111050
Google Scholar
Digital Library
- Ugo Dal Lago, Francesco Gavazzo, and Paul Blain Levy. 2017. Effectful applicative bisimilarity: Monads, relators, and Howe’s method. In 32nd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2017, Reykjavik, Iceland, June 20-23, 2017. IEEE Computer Society, 1–12. https://doi.org/10.1109/LICS.2017.8005117
Google Scholar
Cross Ref
- Thomas Letan, Yann Régis-Gianas, Pierre Chifflier, and Guillaume Hiet. 2018. Modular Verification of Programs with Effects and Effect Handlers in Coq. In FM 2018 - 22nd International Symposium on Formal Methods (LNCS, Vol. 10951). Springer, Oxford, United Kingdom. 338–354. https://doi.org/10.1007/978-3-319-95582-7_20
Google Scholar
Cross Ref
- Yao Li and Stephanie Weirich. 2022. Program Adverbs and Tlön Embeddings. Proc. ACM Program. Lang., 3, ICFP (2022), Article 101, https://doi.org/10.1145/3547632
Google Scholar
Digital Library
- Sheng Liang and Paul Hudak. 2000. Modular Denotational Semantics for Compiler Construction. Lecture Notes in Computer Science, 1058 (2000), 05, isbn:978-3-540-61055-7 https://doi.org/10.1007/3-540-61055-3_39
Google Scholar
Cross Ref
- Sheng Liang, Paul Hudak, and Mark Jones. 1995. Monad Transformers and Modular Interpreters. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’95). Association for Computing Machinery, New York, NY, USA. 333–343. isbn:0897916921 https://doi.org/10.1145/199448.199528
Google Scholar
Digital Library
- Kenji Maillard, Danel Ahman, Robert Atkey, Guido Martínez, Cătălin Hriţcu, Exequiel Rivas, and Éric Tanter. 2019. Dijkstra Monads for All. Proc. ACM Program. Lang., 3, ICFP (2019), Article 104, jul, 29 pages. https://doi.org/10.1145/3341708
Google Scholar
Digital Library
- Kenji Maillard, Cătălin Hriţcu, Exequiel Rivas, and Antoine Van Muylder. 2020. The next 700 Relational Program Logics. Proc. ACM Program. Lang., 4, POPL (2020), Article 4, dec, 33 pages. https://doi.org/10.1145/3371072
Google Scholar
Digital Library
- Conor McBride. 2015. Turing-Completeness Totally Free. In Mathematics of Program Construction - 12th International Conference, MPC 2015, Königswinter, Germany, June 29 - July 1, 2015. Proceedings, Ralf Hinze and Janis Voigtländer (Eds.) (Lecture Notes in Computer Science, Vol. 9129). Springer, 257–275. https://doi.org/10.1007/978-3-319-19797-5_13
Google Scholar
Cross Ref
- John C. Mitchell. 1996. Foundations for Programming Languages. The MIT Press.
Google Scholar
Digital Library
- Eugenio Moggi. 1989. Computational Lambda-Calculus and Monads. In Proceedings of the Fourth Annual Symposium on Logic in Computer Science (LICS ’89), Pacific Grove, California, USA, June 5-8, 1989. IEEE Computer Society, 14–23. https://doi.org/10.1109/LICS.1989.39155
Google Scholar
- Eugenio Moggi. 1990. An Abstract View of Programming Languages. Laboratory for the Foundations of Computer Science, University of Edinburgh.
Google Scholar
- Eugenio Moggi. 1991. Notions of Computation and Monads. Inf. Comput., 93, 1 (1991), 55–92. https://doi.org/10.1016/0890-5401(91)90052-4
Google Scholar
Digital Library
- Aleksandar Nanevski, Anindya Banerjee, and Deepak Garg. 2013. Dependent Type Theory for Verification of Information Flow and Access Control Policies. ACM Trans. Program. Lang. Syst., 35, 2 (2013), 6:1–6:41. https://doi.org/10.1145/2491522.2491523
Google Scholar
Digital Library
- Simon L. Peyton Jones and Philip Wadler. 1993. Imperative Functional Programming. In Proceedings of the 20th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’93). Association for Computing Machinery, New York, NY, USA. 71–84. isbn:0897915607 https://doi.org/10.1145/158511.158524
Google Scholar
Digital Library
- Maciej Piróg and Jeremy Gibbons. 2014. The Coinductive Resumption Monad. In Proceedings of the 30th Conference on the Mathematical Foundations of Programming Semantics, MFPS 2014, Ithaca, NY, USA, June 12-15, 2014, Bart Jacobs, Alexandra Silva, and Sam Staton (Eds.) (Electronic Notes in Theoretical Computer Science, Vol. 308). Elsevier, 273–288. https://doi.org/10.1016/j.entcs.2014.10.015
Google Scholar
Digital Library
- Gordon Plotkin and Matija Pretnar. 2009. Handlers of Algebraic Effects. In Proceedings of the 18th European Symposium on Programming Languages and Systems: Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2009 (ESOP ’09). Springer-Verlag, Berlin, Heidelberg. 80–94. isbn:9783642005893 https://doi.org/10.1007/978-3-642-00590-9_7
Google Scholar
Digital Library
- Gordon D. Plotkin and John Power. 2003. Algebraic Operations and Generic Effects. Appl. Categorical Struct., 11, 1 (2003), 69–94. https://doi.org/10.1023/A:1023064908962
Google Scholar
Cross Ref
- Gordon D Plotkin and Matija Pretnar. 2013. Handling Algebraic Effects. Logical Methods in Computer Science, 9, 4 (2013), Dec., https://doi.org/10.2168/LMCS-9(4:23)2013
Google Scholar
Cross Ref
- Davide Sangiorgi. 2012. Introduction to Bisimulation and Coinduction (2nd ed.). Cambridge University Press, USA. isbn:9781107003637
Google Scholar
- Bas Spitters and Eelis van der Weegen. 2011. Type classes for mathematics in type theory. Math. Struct. Comput. Sci., 21, 4 (2011), 795–825. https://doi.org/10.1017/S0960129511000119
Google Scholar
Cross Ref
- Guy L. Steele. 1994. Building Interpreters by Composing Monads. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’94). Association for Computing Machinery, New York, NY, USA. 472–492. isbn:0897916360 https://doi.org/10.1145/174675.178068
Google Scholar
Digital Library
- Nikhil Swamy, Catalin Hritcu, Chantal Keller, Aseem Rastogi, Antoine Delignat-Lavaud, Simon Forest, Karthikeyan Bhargavan, Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean Karim Zinzindohoue, and Santiago Zanella Béguelin. 2016. Dependent types and multi-monadic effects in F. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20 - 22, 2016, Rastislav Bodík and Rupak Majumdar (Eds.). ACM, 256–270. https://doi.org/10.1145/2837614.2837655
Google Scholar
Digital Library
- Wouter Swierstra. 2008. Data types à la carte. J. Funct. Program., 18, 4 (2008), 423–436. https://doi.org/10.1017/S0956796808006758
Google Scholar
Digital Library
- Wouter Swierstra and Tim Baanen. 2019. A Predicate Transformer Semantics for Effects (Functional Pearl). Proc. ACM Program. Lang., 3, ICFP (2019), Article 103, July, 26 pages. https://doi.org/10.1145/3341707
Google Scholar
Digital Library
- Philip Wadler. 1990. Comprehending Monads. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming (LFP ’90). Association for Computing Machinery, New York, NY, USA. 61–78. isbn:089791368X https://doi.org/10.1145/91556.91592
Google Scholar
Digital Library
- Li-yao Xia, Yannick Zakowski, Paul He, Chung-Kil Hur, Gregory Malecha, Benjamin C. Pierce, and Steve Zdancewic. 2020. Interaction Trees. Proceedings of the ACM on Programming Languages, 4, POPL (2020), https://doi.org/10.1145/3371119
Google Scholar
Digital Library
- Irene Yoon, Yannick Zakowski, and Steve Zdancewic. 2022. Formal Reasoning About Layered Monadic Interpreters. https://doi.org/10.5281/zenodo.6913915
Google Scholar
Digital Library
- Yannick Zakowski, Calvin Beck, Irene Yoon, Ilia Zaichuk, Vadim Zaliva, and Steve Zdancewic. 2021. Modular, Compositional, and Executable Formal Semantics for LLVM IR. Proc. ACM Program. Lang., 5, ICFP (2021), Article 67, aug, 30 pages. https://doi.org/10.1145/3473572
Google Scholar
Digital Library
- Vadim Zaliva, Ilia Zaichuk, and Franz Franchetti. 2020. Verified Translation Between Purely Functional and Imperative Domain Specific Languages in HELIX. In Proceedings of the 12th Working Conference on Verified Software: Theories, Tools, and Experiments (VSTTE). https://doi.org/10.1007/978-3-030-63618-0_3
Google Scholar
Digital Library
- Jianzhou Zhao, Santosh Nagarakatte, Milo M. K. Martin, and Steve Zdancewic. 2012. Formalizing the LLVM Intermediate Representation for Verified Program Transformations. In Proc. of the ACM Symposium on Principles of Programming Languages (POPL). https://doi.org/10.1145/2103621.2103709
Google Scholar
Digital Library
Index Terms
Formal reasoning about layered monadic interpreters
Recommendations
Interaction trees: representing recursive and impure programs in Coq
Interaction trees (ITrees) are a general-purpose data structure for representing the behaviors of recursive programs that interact with their environments. A coinductive variant of “free monads,” ITrees are built out of uninterpreted events and their ...
Coinductive big-step operational semantics
Using a call-by-value functional language as an example, this article illustrates the use of coinductive definitions and proofs in big-step operational semantics, enabling it to describe diverging evaluations in addition to terminating evaluations. We ...
Coalgebraic Reasoning in Coq: Bisimulation and the λ-Coiteration Scheme
Types for Proofs and ProgramsIn this work we present a modular theory of the coalgebras and bisimulation in the intensional type theory implemented in <em>coq</em> . On top of that we build the theory of weakly final coalgebras and develop the <em>λ</em> -coiteration scheme, ...






Comments