A Hierarchy of Monadic Effects for Program Verification Using Equational Reasoning

  • Reynald AffeldtEmail author
  • David Nowak
  • Takafumi Saikawa
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 11825)


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.



We acknowledge the support of the JSPS-CNRS bilateral program “FoRmal tools for IoT sEcurity” (PRC2199) and the JSPS KAKENHI Grant Number 18H03204, and thank all the participants of these projects for fruitful discussions. In particular, we thank Jacques Garrigue and Samuel Hym for taking the time to have extended discussions and giving us feedback on drafts of this paper. We also thank Cyril Cohen and Shinya Katsumata for comments about the formalization of monads.

Supplementary material


  1. 1.
    Abou-Saleh, F., Cheung, K.H., Gibbons, J.: Reasoning about probability and nondeterminism. In: Workshop on Probabilistic Programming Semantics, St. Petersburg, FL, USA, 23 January 2016, January 2016Google Scholar
  2. 2.
    Affeldt, R., Cohen, C., Rouhling, D.: Formalization techniques for asymptotic reasoning in classical analysis. J. Formaliz. Reason. 11(1), 43–76 (2018)MathSciNetzbMATHGoogle Scholar
  3. 3.
    Affeldt, R., Garrigue, J., Nowak, D., Saikawa, T.: A Coq formalization of monadic equational reasoning (2018).
  4. 4.
    Affeldt, R., et al.: A Coq formalization of information theory and linear error-correcting codes (2018).
  5. 5.
    Appel, A.W., Blazy, S.: Separation logic for small-step cminor. In: Schneider, K., Brandt, J. (eds.) TPHOLs 2007. LNCS, vol. 4732, pp. 5–21. Springer, Heidelberg (2007). Scholar
  6. 6.
    Chen, Y.-F., Hong, C.-D., Lengál, O., Mu, S.-C., Sinha, N., Wang, B.-Y.: An executable sequential specification for spark aggregation. In: El Abbadi, A., Garbinato, B. (eds.) NETYS 2017. LNCS, vol. 10299, pp. 421–438. Springer, Cham (2017). Scholar
  7. 7.
    Cheung, K.H.: Distributive Interaction of Algebraic Effects. Ph.D. thesis, Merton College, University of Oxford (2017)Google Scholar
  8. 8.
    Cock, D.: Verifying probabilistic correctness in Isabelle with pGCL. In: 7th Systems Software Verification, Sydney, Australia, pp. 1–10, November 2012Google Scholar
  9. 9.
    Delaware, B., Keuchel, S., Schrijvers, T., d. S. Oliveira, B.C.: Modular monadic meta-theory. In: ACM SIGPLAN International Conference on Functional Programming (ICFP 2013), Boston, MA, USA, 25–27 September 2013, pp. 319–330 (2013)Google Scholar
  10. 10.
    Fischer, S., Kiselyov, O., Shan, C.: Purely functional lazy nondeterministic programming. J. Funct. Program. 21(4–5), 413–465 (2011)MathSciNetCrossRefGoogle Scholar
  11. 11.
    Garillot, F., Gonthier, G., Mahboubi, A., Rideau, L.: Packaging mathematical structures. In: Berghofer, S., Nipkow, T., Urban, C., Wenzel, M. (eds.) TPHOLs 2009. LNCS, vol. 5674, pp. 327–342. Springer, Heidelberg (2009). Scholar
  12. 12.
    Gibbons, J.: Unifying theories of programming with monads. In: Wolff, B., Gaudel, M.-C., Feliachi, A. (eds.) UTP 2012. LNCS, vol. 7681, pp. 23–67. Springer, Heidelberg (2013). Scholar
  13. 13.
    Gibbons, J., Hinze, R.: Just do it: simple monadic equational reasoning. In: 16th ACM SIGPLAN International Conference on Functional Programming (ICFP 2011), Tokyo, Japan, 19–21 September 2011, pp. 2–14. ACM (2011)Google Scholar
  14. 14.
    Gonthier, G., Mahboubi, A.: An introduction to small scale reflection in Coq. J. Formaliz. Reasoning 3(2), 95–152 (2010)MathSciNetzbMATHGoogle Scholar
  15. 15.
    Gonthier, G., Tassi, E.: A language of patterns for subterm selection. In: Beringer, L., Felty, A. (eds.) ITP 2012. LNCS, vol. 7406, pp. 361–376. Springer, Heidelberg (2012). Scholar
  16. 16.
    Greenaway, D.: Automated Proof-Producing Abstraction of C Code. Ph.D. thesis, University of New South Wales, Sydney, Australia, January 2015Google Scholar
  17. 17.
    Hirschowitz, A., Maggesi, M.: Modules over monads and initial semantics. Inf. Comput. 208(5), 545–564 (2010)MathSciNetCrossRefGoogle Scholar
  18. 18.
    Jacobs, B.: Convexity, duality and effects. In: Calude, C.S., Sassone, V. (eds.) TCS 2010. IFIP AICT, vol. 323, pp. 1–19. Springer, Heidelberg (2010). Scholar
  19. 19.
    Jomaa, N., Nowak, D., Grimaud, G., Hym, S.: Formal proof of dynamic memory isolation based on MMU. Sci. Comput. Program. 162, 76–92 (2018)CrossRefGoogle Scholar
  20. 20.
    Jomaa, N., Torrini, P., Nowak, D., Grimaud, G., Hym, S.: Proof-oriented design of a separation kernel with minimal trusted computing base. In: 18th International Workshop on Automated Verification of Critical Systems (AVOCS 2018), July 2018. Oxford, UK. Electronic Communications of the EASST Open Access Journal (2018)Google Scholar
  21. 21.
    Jones, M.P., Duponcheel, L.: Composing monads. Technical report YALEU/DCS/RR-1004, Yale University (Dec 1993)Google Scholar
  22. 22.
    King, D.J., Wadler, P.: Combining monads. In: Launchbury, J., Sansom, P. (eds.) Functional Programming, Glasgow 1992. Workshops in Computing, pp. 134–143. Springer, London (1992)Google Scholar
  23. 23.
    Letan, T., Régis-Gianas, Y., Chifflier, P., Hiet, G.: Modular verification of programs with effects and effect handlers in Coq. In: Havelund, K., Peleska, J., Roscoe, B., de Vink, E. (eds.) FM 2018. LNCS, vol. 10951, pp. 338–354. Springer, Cham (2018). Scholar
  24. 24.
    Lochbihler, A., Schneider, J.: Equational reasoning with applicative functors. In: Blanchette, J.C., Merz, S. (eds.) ITP 2016. LNCS, vol. 9807, pp. 252–273. Springer, Cham (2016). Scholar
  25. 25.
    Mac Lane, S. (ed.): Categories for the Working Mathematician. GTM, vol. 5. Springer, New York (1978). Scholar
  26. 26.
    Mahboubi, A., Tassi, E.: Mathematical Components (2016)., with contributions by Yves Bertot and Georges Gonthier. Version of 2018/08/11
  27. 27.
    Martin-Dorel, E., Tassi, E.: SSReflect in Coq 8.10. In: The Coq Workshop 2019, Portland, OR, USA, 8 September 2019, pp. 1–2, September 2019Google Scholar
  28. 28.
    Moggi, E.: Computational lambda-calculus and monads. In: LICS, pp. 14–23. IEEE Computer Society (1989)Google Scholar
  29. 29.
    Mu, S.C.: Functional pearls, reasoning and derivation of monadic programs, a case study of non-determinism and state, July 2017, draft. Accessed 10 July 2019
  30. 30.
    Mu, S.C.: Calculating a backtracking algorithm: an exercise in monadic program derivation. Technical report TR-IIS-19-003, Institute of Information Science, Academia Sinica, June 2019Google Scholar
  31. 31.
    Mu, S.C.: Equational reasoning for non-deterministic monad: a case study of Spark aggregation. Technical report TR-IIS-19-002, Institute of Information Science, Academia Sinica, June 2019Google Scholar
  32. 32.
    Mu, S., Ko, H., Jansson, P.: Algebra of programming in Agda: dependent types for relational program derivation. J. Funct. Program. 19(5), 545–579 (2009)MathSciNetCrossRefGoogle Scholar
  33. 33.
    Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 1988), Atlanta, GA, USA, 22–24 June 1988, pp. 199–208. ACM (1988)Google Scholar
  34. 34.
    Piróg, M., Gibbons, J.: Tracing monadic computations and representing effects. In: 4th Workshop on Mathematically Structured Functional Programming (MSFP 2012). EPTCS, Tallinn, Estonia, 25 March 2012, vol. 76, pp. 90–111 (2012)CrossRefGoogle Scholar
  35. 35.
    Plotkin, G., Power, J.: Notions of computation determine monads. In: Nielsen, M., Engberg, U. (eds.) FoSSaCS 2002. LNCS, vol. 2303, pp. 342–356. Springer, Heidelberg (2002). Scholar
  36. 36.
    Pretnar, M.: An introduction to algebraic effects and handlers (invited tutorial paper). Electr. Notes Theor. Comput. Sci. 319, 19–35 (2015)MathSciNetCrossRefGoogle Scholar
  37. 37.
    Shan, C.C.: Equational reasoning for probabilistic programming. In: POPL 2018 TutorialFest, January 2018Google Scholar
  38. 38.
    Varacca, D., Winskel, G.: Distributing probability over non-determinism. Math. Struct. Comput. Sci. 16(1), 87–113 (2006)MathSciNetCrossRefGoogle Scholar
  39. 39.
    Voevodsky, V., Ahrens, B., Grayson, D., et al.: UniMath-a computer-checked library of univalent mathematics.
  40. 40.
    Wadler, P.: Comprehending monads. In: LISP and Functional Programming, pp. 61–78 (1990)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.National Institute of Advanced Industrial Science and TechnologyTsukubaJapan
  2. 2.Univ. Lille, CNRS, Centrale Lille, UMR 9189 - CRIStAL - Centre de Recherche en Informatique Signal et Automatique de LilleLilleFrance
  3. 3.Nagoya University & Peano System Inc.NagoyaJapan

Personalised recommendations