One Monad to Prove Them All is a modern fairy tale about curiosity and perseverance, two important properties of a successful PhD student. We follow the PhD student Mona on her adventure of proving properties about Haskell programs in the proof assistant Coq. On the one hand, as a PhD student in computer science Mona observes an increasing demand for correct software products. In particular, because of the large amount of existing software, verifying existing software products becomes more important. Verifying programs in the functional programming language Haskell is no exception. On the other hand, Mona is delighted to see that communities in the area of theorem proving are becoming popular. Thus, Mona sets out to learn more about the interactive theorem prover Coq and verifying Haskell programs in Coq. To prove properties about a Haskell function in Coq, Mona has to translate the function into Coq code. As Coq programs have to be total and Haskell programs are often not, Mona has to model partiality explicitly in Coq. In her quest for a solution Mona finds an ancient manuscript that explains how properties about Haskell functions can be proven in the proof assistant Agda by translating Haskell programs into monadic Agda programs. By instantiating the monadic program with a concrete monad instance the proof can be performed in either a total or a partial setting. Mona discovers that the proposed transformation does not work in Coq due to a restriction in the termination checker. In fact the transformation does not work in Agda anymore as well, as the termination checker in Agda has been improved. We follow Mona on an educational journey through the land of functional programming where she learns about concepts like free monads and containers as well as basics and restrictions of proof assistants like Coq. These concepts are well-known individually, but their interplay gives rise to a solution for Mona's problem based on the originally proposed monadic tranformation that has not been presented before. When Mona starts to test her approach by proving a statement about simple Haskell functions, she realizes that her approach has an additional advantage over the original idea in Agda. Mona's final solution not only works for a specific monad instance but even allows her to prove monad-generic properties. Instead of proving properties over and over again for specific monad instances she is able to prove properties that hold for all monads representable by a container-based instance of the free monad. In order to strengthen her confidence in the practicability of her approach, Mona evaluates her approach in a case study that compares two implementations for queues. In order to share the results with other functional programmers the fairy tale is available as a literate Coq file. If you are a citizen of the land of functional programming or are at least familiar with its customs, had a journey that involved reasoning about functional programs of your own, or are just a curious soul looking for the next story about monads and proofs, then this tale is for you.
[1]
Jan Christiansen,et al.
Probabilistic Functional Logic Programming
,
2018,
PADL.
[2]
Oleg Kiselyov,et al.
Freer monads, more extensible effects
,
2015,
Haskell.
[3]
Nils Anders Danielsson,et al.
Fast and loose reasoning is morally correct
,
2006,
POPL '06.
[4]
Benjamin C. Pierce,et al.
From C to interaction trees: specifying, verifying, and testing a networked server
,
2018,
CPP.
[5]
Robert Atkey,et al.
Interleaving data and effects
,
2015,
J. Funct. Program..
[6]
Conor McBride.
Turing-Completeness Totally Free
,
2015,
MPC.
[7]
Ulf Norell,et al.
Verifying haskell programs using constructive type theory
,
2005,
Haskell '05.
[8]
Daniel Seidel,et al.
Free theorems for functional logic programs
,
2010,
PLPV '10.
[9]
Sebastian Fischer,et al.
Purely functional lazy non-deterministic programming
,
2009,
Journal of Functional Programming.
[10]
Wouter Swierstra,et al.
Data types à la carte
,
2008,
Journal of Functional Programming.
[11]
Josef Svenningsson.
Shortcut fusion for accumulating parameters & zip-like functions
,
2002,
ICFP '02.
[12]
Thorsten Altenkirch,et al.
Foundations of Software Science and Computation Structures: 6th International Conference, FOSSACS 2003 Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2003 Warsaw, Poland, April 7–11, 2003 Proceedings
,
2003,
Lecture Notes in Computer Science.
[13]
Koen Claessen,et al.
QuickCheck: a lightweight tool for random testing of Haskell programs
,
2000,
ICFP.
[14]
Tom Schrijvers,et al.
Generic datatypes à la carte
,
2013,
WGP '13.
[15]
Peter Morris,et al.
Generic Programming with Dependent Types
,
2006,
SSDGP.
[16]
Yann Régis-Gianas,et al.
Modular Verification of Programs with Effects and Effect Handlers in Coq
,
2018,
FM.
[17]
Thierry Coquand,et al.
Inductively defined types
,
1988,
Conference on Computer Logic.
[18]
Tarmo Uustalu.
Container Combinatorics: Monads and Lax Monoidal Functors
,
2017,
TTCS.
[19]
Patricia Johann,et al.
Free theorems in the presence of seq
,
2004,
POPL.
[20]
Antal Spector-Zabusky,et al.
Ready, set, verify! applying hs-to-coq to real-world Haskell code (experience report)
,
2018,
Journal of Functional Programming.
[21]
Lutz Straßburger,et al.
Parametricity and Proving Free Theorems for Functional-Logic Languages
,
2014,
PPDP '14.