arXiv:2610.23604cs.PLOct 2026

Manuscript Offprint

arXiv:2610.23604

A Taxonomy of Predicate Transformer Monads for Specifying Monadic Programs

Abigail Pribisova, Yao Li, Catalin Hritcu, Cezar-Constantin Andrici, Kenji Maillard, Exequiel Rivas

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abigail Pribisova 1^{1} D◯\textcircled{D}, Yao Li 2^{2} D◯\textcircled{D}, Cezar-Constantin Andrici 1^{1} D◯\textcircled{D}, Cătălin Hritcu 1^{1} D◯\textcircled{D}, Kenji Maillard 3^{3} D◯\textcircled{D}, and Exequiel Rivas 4^{4} D◯\textcircled{D}

1^{1} MPI-SP, Bochum, Germany

{abigail.pribisova,cezar.andrici,catalin.hritcu}@mpi-sp.org

2^{2} Portland State University, USA liyao@pdx.edu

3^{3} Inria, Nantes, France kenji.maillard@inria.fr

4^{4} Tallinn University of Technology, Estonia execuiel.rivas@ttu.ee

Abstract. Monads of weakest precondition predicate transformers are the foundation of several verification frameworks for monadic programs. For specifying monadic computations with nondeterminism and nontermination, in addition to weakest preconditions, we introduce the first strongest postcondition monads covering all combinations of angelic or demonic nondeterminism and partial or total interpretations of nontermination. For extending these base strongest postcondition monads with side effects such as mutable state, monad transformers do not yield the expected monads, so we instead generalize the base monads to arrows and use arrow transformers. We give a taxonomy of weakest precondition and strongest postcondition monads, for the base monads and for their versions with state, and show that the known relationships between under- and over-approximate triples based on predicate transformers already hold at the level of the predicate transformers themselves. We use the predicate transformer monads to define under- and over-approximate triples and, where possible, Dijkstra monads. Finally, we relate these two specification styles.

Keywords: strongest postcondition · weakest precondition · monads · arrows · program logics · under-approximation · over-approximation

1 Introduction

Program logics provide a formal way to specify what programs can or should do, and to verify that programs meet their specifications. For programs with non-determinism, a logic usually either takes a demonic interpretation, requiring all executions to satisfy the specification, or an angelic one requiring the existence of such an execution. For divergence, a total interpretation requires termination, while a partial/liberal one allows divergence. These logics are often presented as deductive systems over triples relating a precondition p, a program c, and a post-condition q. The semantics of triples can often be phrased via Dijkstra's weakest precondition (wp) or strongest postcondition (sp) predicate transformers [10–12].

Pribisova et al.

For example, the triple {p}c{q}\{p\}c\{q\} is valid in partial correctness Hoare logic [3, 16] exactly when p⇒dwlp[c](q)p \Rightarrow dwlp[c](q), where dwlp is the demonic, liberal wp variant [11]. In fact, this logic admits a second such characterization [37]: the triple is also valid exactly when asp[c](p)⇒qasp[c](p) \Rightarrow q, for aspasp, the angelic, total sp variant.

These predicate transformer characterizations of triples are not limited to reasoning about correctness. O'Hearn's incorrectness logic [30], which specifies which states a program can reach (e.g., error states), uses the same transformer with the implication reversed; the triple [p]c[q][p]c[q] is valid exactly when q⇒asp[c](p)q \Rightarrow asp[c](p). Unlike Hoare logic, there is no equivalent wp characterization [37]. Incorrectness logic triples are called under-approximate, as q under-approximates the reachable states asp[c](p)asp[c](p). In contrast, Hoare logic triples are over-approximate, as q over-approximates the reachable states. For simple imperative programs, Verscht and Kaminski [37] taxonomize these under- and over-approximate triples for four wp variants and four sp variants [37, 39], corresponding to the standard interpretations of nondeterminism and nontermination: angelic-demonic and total-liberal. 5^{5}

Triples and wps have also been used to verify monadic programs [13, 14, 26, 28, 29, 32–35], which can be shallowly embedded in proof assistants, making verification convenient. A key insight was that the specifications of monadic programs also have monadic structure, so they compose with ret and bind as the programs do. Swamy et al. [33, 34] showed that wps form such a monad. But how do we define wps modularly, one effect at a time? Maillard et al. [26] observe that if we start with a base monotone wp monad WPure(A):=(A→P)→P\mathsf{W}^{\text{Pure}}(\mathsf{A}) := (\mathsf{A} \to \mathbb{P}) \to \mathbb{P}, where P\mathbb{P} is the type of propositions, we can add effects with the same monad transformers as for computation monads. For instance, the state monad transformer turns WPure\mathsf{W}^{\text{Pure}} into the usual monad of stateful wps, of type StT(WPure)(S,A):=S→(A×S→P)→P≅(A×S→P)→(S→P)\mathsf{StT}(\mathsf{W}^{\text{Pure}})(\mathsf{S}, \mathsf{A}) := \mathsf{S} \to (\mathsf{A} \times \mathsf{S} \to \mathbb{P}) \to \mathbb{P} \cong (\mathsf{A} \times \mathsf{S} \to \mathbb{P}) \to (\mathsf{S} \to \mathbb{P}). Such wp monads have been used in verification frameworks including F∗\mathsf{F}^* [2, 26, 33, 34] and Loom [14].

Monads of sps are less understood. For a start, monotone sps alone do not form a lawful monad. Maillard et al. obtain a base sp monad of type SPost(A) := P → (A → P) by further restricting the carrier to predicate transformers whose postconditions imply the precondition. We observe that the resulting monad can specify not only pure programs, but also nondeterministic and nonterminating ones, under an angelic and total interpretation. In this paper we introduce the first sp monads for all four interpretations of nondeterminism and nontermination by instead restricting the carrier to standard classes of predicate transformers [8]: the angelic monad variants are disjunctive (i.e., preserve potentially infinite non-empty disjunctions), demonic ones conjunctive (i.e., preserve such conjunctions), total ones strict (i.e., ⊥ precondition results in ⊥ postcondition), and liberal ones terminating (i.e., ⊥ precondition results in ⊥

5^{5} For sps, angelic and demonic refer to whether some or all of the initial states from which a final state is reachable must satisfy the precondition. This matters when several initial states reach the same final state, even in deterministic programs [37]. Similarly, the postcondition of a total sp only contains final states reached from the precondition, while that of a liberal sp also contains final states that nothing reaches.

postcondition). Applying similar restrictions to the monotone wp monad gives one wp monad per interpretation. While these four wp monads are submonads of the WPure monad above, the four sp monads are more interesting, since each of them needs its own ret and bind tailored to its carrier restriction.

When also considering effects such as state, a further challenge is effect modularity: adding the ability to reason about new effects by applying a monad transformer, which yields a lawful monad for free. The state monad transformer, however, does not turn these base sp monads into the monads we expect for stateful sps, producing instead: StT(SPost)(S,A)=S→P→(A×S→P)\text{StT}(S\text{Post})(S, A) = S \to \mathbb{P} \to (A \times S \to \mathbb{P}). Such an sp takes one initial state and, separately, one precondition proposition, whereas a stateful sp should take a precondition that is a predicate over initial states, as in the type (S→P)→(A×S→P)(S \to \mathbb{P}) \to (A \times S \to \mathbb{P}). Underlying this is a more basic challenge: even setting modularity aside, there was no known way to construct lawful stateful sp monads of the expected shape, which need a restricted carrier and a matching ret and bind, separately for each of the four interpretations.

We solve both challenges by generalizing our sp monads to Hughes arrows with application [17], since arrow transformers then yield stateful sp monads of the expected shape in an effect-modular way. We start with a base arrow of type SPArr(B, A) := (B → P) → (A → P) satisfying a variant of the carrier restrictions above. By fixing the input type B to unit, an arrow with application yields a monad [24]:

SP(A):=SPArr(unit,A)=(unit→P)→(A→P)≅P→(A→P)\mathsf{SP}(\mathsf{A}):=\mathsf{SPArr}(\mathsf{unit},\mathsf{A})=(\mathsf{unit}\to\mathbb{P})\to(\mathsf{A}\to\mathbb{P})\cong\mathbb{P}\to(\mathsf{A}\to\mathbb{P})

Moreover, since arrows have an input type, which arrow transformers can extend, applying the state arrow transformer gives us StArrT(SP)(S,B,A)=(B×S→P)→(A×S→P)\text{StArrT}(SP)(S, B, A) = (B \times S \to \mathbb{P}) \to (A \times S \to \mathbb{P}), which, when the input type is fixed, provides the expected shape of a stateful sp monad. Crucially, the resulting stateful monads inherit the carrier restriction and lawfulness of the base arrow, since the state arrow transformer only adds the state to the input and output types.

This allows us to give a taxonomy of these base and stateful sp and wp monads (Fig. 1, in §4) and show that the relationships established by Verscht and Kaminski [37] between under- and over-approximate triples already hold for the predicate transformers themselves. Additionally, we use the predicate transformer monads to define under- and over-approximate triples and, where possible, Dijkstra monads [2, 26, 33]. A Dijkstra monad is a monad-like structure of computations indexed by elements of a specification monad [26]. A specification monad is ordered by specification precision so that bind is monotone [15, 20].

We make the following contributions:

▶ We introduce the first lawful sp monads covering all four interpretations of nondeterminism and nontermination. They are derived from arrows with application restricted to preserve non-empty disjunctions (angelic) or conjunctions (demonic), and ⊥ (total) or ⊥ (liberal). This allows adding state using arrow transformers, whereas monad transformers do not yield the expected monads. We also obtain four base wp monads by applying similar restrictions directly to the monotone wp monad [26]. Unlike the wp monads, which are all submonads of the same monad, each sp monad has its own ret and bind.

Pribisova et al.

▶ We recast Verscht and Kaminski's taxonomy of triples [37] as a taxonomy of the eight wp and sp monads, and show that the relationships they establish between under- and over-approximate triples already hold for predicate transformers, both for the base monads and for their versions with state.

▶ We construct triples (precondition, monadic computation, postcondition) in terms of monad morphisms from our base computation monad of nondeterminism and nontermination into our eight wp and sp monads. We also add state and exceptions to both the computation monad and the wp and sp monads and lift the monad morphisms for free, through monad transformers as in DM4All [2, 26] and through arrow transformers for the sps. This, for instance, allows us to define the semantics of incorrectness logic triples [p]c[q][p]c[q] for monadic programs cc as q⇒asp[c](p)q \Rightarrow asp[c](p), analogous to O'Hearn's original definition above [30]. We use the monad morphisms to prove that simple programs satisfy triples for both correctness and incorrectness in a style inspired by Loom [14], though focused not on automation but on generality, since we consider both over- and under-approximation, sps, and general wps.

▶ We show that our new asp and dslp monads and all wp monads form specification monads [26]. This lets us verify monadic programs by comparing the specification produced by one of our monad morphisms with the intended specification using the specification monad's order. This covers both over- and under-approximation by flipping the order, and as for triples, we use this to verify simple monadic programs. As these predicate transformer monads are specification monads, our monad morphisms targeting them give rise to Dijkstra monads [26]. The dsp and aslp monads have binds that are not monotone with respect to their natural orders, so they are not specification monads, which limits how specifications can be weakened and composed.

▶ For intended specifications expressed as triples, we show that the Loom-inspired verification style and the Dijkstra monad-inspired one are conceptually equivalent for the specification monads based on wps as well as over-approximate asp and under-approximate dslp. This requires turning triples into predicate transformers, which we show is possible for the specification monads above, but not for under-approximate asp and over-approximate dslp.

To study the expressive power of our stateful sp and wp specification monads, we compare them to stateful versions of existing specification monads [26], such as predicates on results Pred(A)=A→P\text{Pred}(A) = A \to \mathbb{P} and pairs of pre- and postconditions, by establishing Galois connections, some of which are isomorphisms. In particular, we show that the known isomorphism [25] between the predicate monad Pred(A)\text{Pred}(A) and the base sp monad of Maillard et al. extends to isomorphisms between asp and dwlp and between dslp and awp as specification monads in the stateful setting.

▶ We fully mechanize all definitions and proofs in Rocq.

Artifact and use of AI. The Rocq development is available at https://github.com/lastland/SpecMonad/tree/main/Code. It was developed in part interactively with the help of AI coding agents (Claude, Codex, and OpenCode), es-pecially for proofs, which are machine-checked by Rocq. Any AI-generated code that affects the trusted computing base (definitions and theorem statements) was carefully reviewed by the authors. AI agents were used to help with IATEX programming and to improve some of the text of the paper; we wrote the original text, checked all proposed improvements, and take full responsibility for the paper and artifact.