Reaching for the Star: Tale of a Monad in Coq

Abstract Monadic programming is an essential component in the toolbox of functional programmers. For the pure and total programmers, who sometimes navigate the waters of certified programming in type theory, it is the only means to concisely implement the imperative traits of certain algorithms. Monads open up a portal to the imperative world, all that from the comfort of the functional world. The trend towards certified programming within type theory begs the question of reasoning about such programs. Effectful programs being encoded as pure programs in the host type theory, we can readily manipulate these objects through their encoding. In this article, we pursue the idea, popularized by Maillard [21], that every monad deserves a dedicated program logic and that, consequently, a proof over a monadic program ought to take place within a Floyd-Hoare logic built for the occasion. We illustrate this vision through a case study on the SimplExpr module of CompCert [18], using a separation logic tailored to reason about the freshness of a monadic gensym.

[1]  Robert Atkey,et al.  Dijkstra monads for all , 2019, Proc. ACM Program. Lang..

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

[3]  Yann Régis-Gianas,et al.  FreeSpec: specifying, verifying, and executing impure computations in Coq , 2020, CPP.

[4]  Santiago Zanella Béguelin,et al.  Dependent types and multi-monadic effects in F , 2016, POPL.

[5]  ARTHUR CHARGUÉRAUD,et al.  Separation logic for sequential programs (functional pearl) , 2020, Proc. ACM Program. Lang..

[6]  Kenji Maillard,et al.  Principles of Program Verification for Arbitrary Monadic Effects. (Principes de la Vérification de Programmes à Effets Monadiques Arbitraires) , 2019 .

[7]  Edwin Brady Resource-Dependent Algebraic Effects , 2014, Trends in Functional Programming.

[8]  Nikhil Swamy,et al.  Recalling a witness: foundations and applications of monotonic state , 2017, Proc. ACM Program. Lang..

[9]  Edwin Brady,et al.  Programming and reasoning with algebraic effects and dependent types , 2013, ICFP.

[10]  Lars Birkedal,et al.  Iris from the ground up: A modular foundation for higher-order concurrent separation logic , 2018, Journal of Functional Programming.

[11]  Jean-Christophe Filliâtre,et al.  Verification of non-functional programs using interpretations in type theory , 2003, J. Funct. Program..

[12]  Wouter Swierstra A Hoare Logic for the State Monad , 2009, TPHOLs.

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

[14]  Arthur Charguéraud Program verification through characteristic formulae , 2010, ICFP '10.

[15]  Chung-Kil Hur,et al.  Interaction trees: representing recursive and impure programs in Coq , 2020, Proc. ACM Program. Lang..

[16]  Robert Atkey,et al.  Parameterised notions of computation , 2006, J. Funct. Program..

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

[18]  J. G. Morrisett,et al.  Ynot: dependent types for imperative programs , 2008, ICFP.

[19]  Michael Hicks,et al.  Polymonadic Programming , 2014, MSFP.

[20]  David A. Basin,et al.  A Monad-Based Modeling and Verification Toolbox with Application to Security Protocols , 2007, TPHOLs.

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

[22]  Gordon D. Plotkin,et al.  Adequacy for Algebraic Effects , 2001, FoSSaCS.

[23]  Gudmund Grov,et al.  An Essence of SSReflect , 2012, AISC/MKM/Calculemus.

[24]  Aaron Stump Programming Language Foundations , 2013 .

[25]  Chapter 25 Reasoning About Effects : Seeing the Wood Through the Trees , 2008 .

[26]  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.

[27]  Simon Peyton Jones,et al.  Tackling the Awkward Squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell , 2005 .

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

[29]  Adam Chlipala,et al.  The End of History? Using a Proof Assistant to Replace Language Design with Library Design , 2017, SNAPL.

[30]  Nikhil Swamy,et al.  SteelCore: an extensible concurrent separation logic for effectful dependently typed programs , 2020, Proc. ACM Program. Lang..

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

[32]  Chung-Kil Hur,et al.  Strongly Typed Term Representations in Coq , 2011, Journal of Automated Reasoning.

[33]  Joseph Tassarotti,et al.  MoSeL: a general, extensible modal framework for interactive proofs in separation logic , 2018, Proc. ACM Program. Lang..

[34]  Reynald Affeldt,et al.  A Hierarchy of Monadic Effects for Program Verification Using Equational Reasoning , 2019, MPC.

[35]  Xavier Leroy,et al.  Formal verification of a realistic compiler , 2009, CACM.