[Paper Review] Certified proofs in programs involving exceptions
This paper presents a certified proof system for programs involving exceptions by extending Moggi's monadic approach with decorated equational reasoning. It enables two-step verification: first proving properties in a pure setting, then incorporating exceptions via semantic decorations, with soundness proven and Coq-verified examples demonstrating exception propagation and handling.
Exception handling is provided by most modern programming languages. It allows to deal with anomalous or exceptional events which require special processing. In computer algebra, exception handling is an efficient way to implement the dynamic evaluation paradigm: for instance, in linear algebra, dynamic evaluation can be used for applying programs which have been written for matrices with coefficients in a field to matrices with coefficients in a ring. Thus, a proof system for computer algebra should include a treatement of exceptions, which must rely on a careful description of a semantics of exceptions. The categorical notion of monad can be used for formalizing the raising of exceptions: this has been proposed by Moggi and implemented in Haskell. In this paper, we provide a proof system for exceptions which involves both raising and handling, by extending Moggi's approach. Moreover, the core part of this proof system is dual to a proof system for side effects in imperative languages, which relies on the categorical notion of comonad. Both proof systems are implemented in the Coq proof assistant.
Motivation & Objective
- To formalize exception handling in a way that supports formal verification of programs involving dynamic evaluation, especially in computer algebra.
- To provide a proof system that separates reasoning about pure computations from reasoning about computational effects like exceptions.
- To extend Moggi's monadic approach to include both exception raising and handling, with duality to state effects via comonads.
- To enable machine-checked proofs in Coq by introducing decorations to syntax and equations that track exception behavior.
- To support hierarchical exception types through subtyping and casting, extending the framework to realistic programming language features.
Proposed method
- The authors introduce a decorated syntax where expressions are annotated with effect information (e.g., pure, exceptional, or both), enabling classification of expressions by their interaction with exceptions.
- They define a core language for exceptions based on the monad X + Exc, where values are either normal results or exceptions, and define operations for tagging, untagging, and handling exceptions.
- Decorated equations distinguish weak equality (up to effects) from strong equality (preserving effects), allowing modular proof construction.
- The proof system is built on the Kleisli category of the exception monad and dualized from the coKleisli category of the state comonad, leveraging categorical duality.
- The framework supports subtyping of exception types via cast operations, with semantics defined to preserve type safety and subtyping invariants.
- All proofs are formalized and machine-checked in the Coq proof assistant, with a dual implementation for state effects available in the same framework.
Experimental results
Research questions
- RQ1How can formal proofs be structured to verify programs with exceptions while maintaining modularity between pure and effectful reasoning?
- RQ2Can a proof system be designed that separates the verification of pure program logic from the reasoning about computational effects like exceptions?
- RQ3How can decorated equational reasoning support both weak and strong equalities in the presence of exceptions?
- RQ4What is the role of duality between state and exception effects in designing a unified proof framework?
- RQ5How can hierarchical exception types and casting be formally integrated into a proof system for exceptions?
Key findings
- The proof system is sound with respect to the denotational semantics of exceptions, as formally established in Theorem 5.5.
- The framework enables two-step verification: first, proofs are checked in the pure fragment by dropping decorations; second, decorations are reactivated to verify effect-sensitive properties.
- A Coq-verified proof demonstrates that a propagator correctly transmits exceptions through composition, using weak and strong equality rules.
- The system supports subtyping of exception types via cast operations, with semantics that preserve type safety and compositionality.
- The approach is dual to a proof system for state effects, enabling a unified treatment of computational effects using monads and comonads.
- The framework has been implemented in Coq and is available at http://coqeffects.forge.imag.fr, demonstrating practical applicability.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.