Dijkstra monads for all

This paper proposes a general semantic framework for verifying programs with arbitrary monadic side-effects using Dijkstra monads, which we define as monad-like structures indexed by a specification monad. We prove that any monad morphism between a computational monad and a specification monad gives rise to a Dijkstra monad, which provides great flexibility for obtaining Dijkstra monads tailored to the verification task at hand. We moreover show that a large variety of specification monads can be obtained by applying monad transformers to various base specification monads, including predicate transformers and Hoare-style pre- and postconditions. For defining correct monad transformers, we propose a language inspired by Moggi's monadic metalanguage that is parameterized by a dependent type theory. We also develop a notion of algebraic operations for Dijkstra monads, and start to investigate two ways of also accommodating effect handlers. We implement our framework in both Coq and F*, and illustrate that it supports a wide variety of verification styles for effects such as exceptions, nondeterminism, state, input-output, and general recursion.

[1]  Paul Hudak,et al.  Monad transformers and modular interpreters , 1995, POPL '95.

[2]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[3]  Juan Chen,et al.  Verifying higher-order programs with the dijkstra monad , 2013, PLDI.

[4]  Gordon D. Plotkin,et al.  A Logic for Algebraic Effects , 2008, 2008 23rd Annual IEEE Symposium on Logic in Computer Science.

[5]  Lars Birkedal,et al.  Ynot: dependent types for imperative programs , 2008, ICFP 2008.

[6]  Alex K. Simpson,et al.  Behavioural Equivalence via Modalities for Algebraic Effects , 2018, ESOP.

[7]  K. Rustan M. Leino,et al.  Efficient weakest preconditions , 2005, Inf. Process. Lett..

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

[9]  WOUTER SWIERSTRA,et al.  A predicate transformer semantics for effects (functional pearl) , 2019, Proc. ACM Program. Lang..

[10]  Peter Dybjer,et al.  The Biequivalence of Locally Cartesian Closed Categories and Martin-Löf Type Theories , 2014, Math. Struct. Comput. Sci..

[11]  Gordon D. Plotkin,et al.  Handling Algebraic Effects , 2013, Log. Methods Comput. Sci..

[12]  Aleksandar Nanevski,et al.  Hoare-style reasoning with (algebraic) continuations , 2013, ICFP.

[13]  J. Gregory Morrisett,et al.  Trace-based verification of imperative programs with I/O , 2011, J. Symb. Comput..

[14]  Paul Blain Levy,et al.  Exploring the Boundaries of Monad Tensorability on Set , 2013, Log. Methods Comput. Sci..

[15]  Thierry Coquand,et al.  Inductively defined types , 1988, Conference on Computer Logic.

[16]  C. A. R. Hoare,et al.  An axiomatic basis for computer programming , 1969, CACM.

[17]  Shin-ya Katsumata,et al.  Parametric effect monads and semantics of effect systems , 2014, POPL.

[18]  Edsger W. Dijkstra,et al.  Guarded commands, nondeterminacy and formal derivation of programs , 1975, Commun. ACM.

[19]  Carroll Morgan,et al.  Programming from specifications (2nd ed.) , 1994 .

[20]  Nick Benton,et al.  Monads and Effects , 2000, APPSEM.

[21]  Shin-ya Katsumata,et al.  Relating computational effects by ⊤⊤-lifting , 2013, Inf. Comput..

[22]  Lauretta O. Osho,et al.  Axiomatic Basis for Computer Programming , 2013 .

[23]  Gordon D. Plotkin,et al.  Algebraic Operations and Generic Effects , 2003, Appl. Categorical Struct..

[24]  Conor McBride Turing-Completeness Totally Free , 2015, MPC.

[25]  Sam Staton,et al.  A Sound and Complete Logic for Algebraic Effects , 2019, FoSSaCS.

[26]  Christoph Rauch,et al.  Generic Hoare Logic for Order-Enriched Effects with Exceptions , 2016, WADT.

[27]  Aaron Stump,et al.  Generic zero-cost reuse for dependent types , 2018, PACMPL.

[28]  Rance Cleaveland,et al.  Implementing mathematics with the Nuprl proof development system , 1986 .

[29]  S. Lindley Reducibility and > >-lifting for Computation Types , 2004 .

[30]  Lars Birkedal,et al.  Hoare type theory, polymorphism and separation1 , 2008, Journal of Functional Programming.

[31]  Ambrus Kaposi,et al.  Signatures and Induction Principles for Higher Inductive-Inductive Types , 2020, Log. Methods Comput. Sci..

[32]  Guillaume Munch-Maccagnoni Syntax and Models of a non-Associative Composition of Programs and Proofs. (Syntaxe et modèles d'une composition non-associative des programmes et des preuves) , 2013 .

[33]  Thorsten Altenkirch,et al.  Partiality, Revisited: The Partiality Monad as a Quotient Inductive-Inductive Type , 2017, FoSSaCS.

[34]  Jeremy Avigad,et al.  The Lean Theorem Prover (System Description) , 2015, CADE.

[35]  Stefan Milius,et al.  Coproducts of Monads on Set , 2012, 2012 27th Annual IEEE Symposium on Logic in Computer Science.

[36]  Danel Ahman Handling fibred algebraic effects , 2018, Proc. ACM Program. Lang..

[37]  Rasmus Ejlers Møgelberg,et al.  The enriched effect calculus: syntax and semantics , 2014, J. Log. Comput..

[38]  Robert W. Floyd,et al.  Nondeterministic Algorithms , 1967, JACM.

[39]  John C. Reynolds,et al.  Separation logic: a logic for shared mutable data structures , 2002, Proceedings 17th Annual IEEE Symposium on Logic in Computer Science.

[40]  Roman Fric,et al.  A Categorical Approach to Probability Theory , 2010, Stud Logica.

[41]  Gordon D. Plotkin,et al.  Combining algebraic effects with continuations , 2007, Theor. Comput. Sci..

[42]  Michèle Giry,et al.  A categorical approach to probability theory , 1982 .

[43]  Deepak Garg,et al.  Dependent Type Theory for Verification of Information Flow and Access Control Policies , 2013, TOPL.

[44]  Pierre-Yves Strub,et al.  Dependent types and multi-monadic effects in F* , 2016, POPL.

[45]  Eugenio Moggi,et al.  Monad transformers as monoid transformers , 2010, Theor. Comput. Sci..

[46]  Bart Jacobs,et al.  Dijkstra and Hoare monads in monadic computation , 2015, Theor. Comput. Sci..

[47]  Eugenio Moggi A Semantics for Evaluation Logic , 1995, Fundam. Informaticae.

[48]  Nikhil Swamy,et al.  Dijkstra monads for free , 2016, POPL.

[49]  Bart Jacobs Comprehension Categories and the Semantics of Type Dependency , 1993, Theor. Comput. Sci..

[50]  Niels F. W. Voorneveld Quantitative Logics for Equivalence of Effectful Programs , 2019, MFPS.

[51]  Ian Stark,et al.  Reducibility and TT-Lifting for Computation Types , 2005, TLCA.

[52]  Christoph Lüth,et al.  Composing monads using coproducts , 2002, ICFP '02.

[53]  Ichiro Hasuo Generic weakest precondition semantics from monads enriched with order , 2015, Theor. Comput. Sci..