A Hierarchy of Monadic Effects for Program Verification Using Equational Reasoning

One can perform equational reasoning about computational effects with a purely functional programming language thanks to monads. Even though equational reasoning for effectful programs is desirable, it is not yet mainstream. This is partly because it is difficult to maintain pencil-and-paper proofs of large examples. We propose a formalization of a hierarchy of effects using monads in the Coq proof assistant that makes equational reasoning practical. Our main idea is to formalize the hierarchy of effects and algebraic laws like it is done when formalizing hierarchy of traditional algebras. We can then take advantage of the sophisticated rewriting capabilities of Coq to achieve concise proofs of programs. We also show how to ensure the consistency of our hierarchy by providing rigorous models. We explain the various techniques we use to formalize a rich hierarchy of effects (with nondeterminism, state, probability, and more), to mechanize numerous examples from the literature, and we furthermore discuss extensions and new applications.

[1]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[2]  David Greenaway,et al.  Automated proof-producing abstraction of C code , 2014 .

[3]  Kwok-Ho Cheung,et al.  Distributive interaction of algebraic effects , 2017 .

[4]  Jeremy Gibbons,et al.  Reasoning about Probability and Nondeterminism , 2016 .

[5]  Philip Wadler,et al.  Combining Monads , 1992 .

[6]  Gilles Grimaud,et al.  Proof-Oriented Design of a Separation Kernel with Minimal Trusted Computing Base , 2018, Electron. Commun. Eur. Assoc. Softw. Sci. Technol..

[7]  Sebastian Fischer,et al.  Purely functional lazy nondeterministic programming , 2011, J. Funct. Program..

[8]  Enrico Tassi,et al.  A Language of Patterns for Subterm Selection , 2012, ITP.

[9]  Ralf Hinze,et al.  Just do it: simple monadic equational reasoning , 2011, ICFP.

[10]  Andrew W. Appel,et al.  Separation Logic for Small-Step cminor , 2007, TPHOLs.

[11]  Gordon D. Plotkin,et al.  Notions of Computation Determine Monads , 2002, FoSSaCS.

[12]  Assia Mahboubi,et al.  An introduction to small scale reflection in Coq , 2010, J. Formaliz. Reason..

[13]  Yann Régis-Gianas,et al.  Modular Verification of Programs with Effects and Effect Handlers in Coq , 2018, FM.

[14]  Shin-Cheng Mu,et al.  An Executable Sequential Specification for Spark Aggregation , 2017, NETYS.

[15]  Gilles Grimaud,et al.  Formal proof of dynamic memory isolation based on MMU , 2018, Sci. Comput. Program..

[16]  Jeremy Gibbons,et al.  Unifying Theories of Programming with Monads , 2012, UTP.

[17]  David Cock,et al.  Verifying Probabilistic Correctness in Isabelle with pGCL , 2012, SSV.

[18]  Matija Pretnar An Introduction to Algebraic Effects and Handlers. Invited tutorial paper , 2015, MFPS.

[19]  Jeremy Gibbons,et al.  Tracing monadic computations and representing effects , 2012, MSFP.

[20]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[21]  André Hirschowitz,et al.  Modules over monads and initial semantics , 2010, Inf. Comput..

[22]  Bart Jacobs,et al.  Convexity, Duality and Effects , 2010, IFIP TCS.

[23]  Bruno C. d. S. Oliveira,et al.  Modular monadic meta-theory , 2013, ICFP.

[24]  Andreas Lochbihler,et al.  Equational Reasoning with Applicative Functors , 2016, ITP.

[25]  Philip Wadler,et al.  Comprehending monads , 1990, LISP and Functional Programming.

[26]  Shin-Cheng Mu,et al.  Algebra of programming in Agda: Dependent types for relational program derivation , 2009, J. Funct. Program..

[27]  Enrico Tassi,et al.  New Results - A book on mathematical components , 2016 .

[28]  S. Lane Categories for the Working Mathematician , 1971 .

[29]  Shin-Cheng Mu Calculating a backtracking algorithm: an exercise in monadic program derivation , 2021 .

[30]  Assia Mahboubi,et al.  Packaging Mathematical Structures , 2009, TPHOLs.

[31]  Reynald Affeldt,et al.  Formalization Techniques for Asymptotic Reasoning in Classical Analysis , 2018, J. Formaliz. Reason..

[32]  Glynn Winskel,et al.  Distributing probability over non-determinism , 2006, Mathematical Structures in Computer Science.

[33]  Philip Wadler,et al.  Comprehending monads , 1990, Mathematical Structures in Computer Science.