Dependent types and multi-monadic effects in F

Nikhil Swamy, Catalin Hritcu, Chantal Keller, Aseem Rastogi, Antoine Delignat-Lavaud, Simon Forest, Karthikeyan Bhargavan, Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean Karim Zinzindohoue, Santiago Zanella-Béguelin

Abstract

F is a dependently typed programming language designed to bridge the gap between interactive proof assistants and automated verification tools. By employing a lattice of Dijkstra monads, F enables the verification of effectful programs—those involving state, exceptions, and non-termination—while maintaining a rigorous mathematical core. This paper discusses the redesign of F*, its memory model based on hyper-heaps, and its practical application in verifying complex systems like the miTLS protocol.

Introduction

In formal methods, a dichotomy exists between interactive proof assistants (e.g., Coq, Agda) and automated verification tools (e.g., Dafny). While the former offer expressive logics for higher-order functional programming, they often struggle with "real-world" side effects. Conversely, automated tools handle state effectively via SMT solvers but lack the logical depth required for complex mathematical proofs. F* addresses this divide by providing a "pay-as-you-go" verification system, allowing developers to write idiomatic code and incrementally add formal specifications for high-assurance software.

Core Methodology: The Lattice of Dijkstra Monads

The primary innovation in F* is its treatment of computational effects through a hierarchy known as a lattice of Dijkstra monads. This structure allows for modular verification by categorizing effects:

  • PURE Monad: Resides at the base of the lattice for functions with no side effects.
  • STATE/EXN Monads: Functions using mutable state or exceptions are "lifted" into these monads.

This modularity prevents verification condition (VC) explosion by keeping the mathematical formulas generated for the SMT solver manageable. F* uses these monads to automatically infer the "weakest precondition" (WP) for code segments, determining the necessary state prior to execution to ensure correctness.

Memory Management and Hyper-heaps

To solve the "framing problem"—proving that modifying one part of the memory does not inadvertently affect another—F introduces hyper-heaps. This model partitions memory into distinct regions. By structuring memory this way, F provides an abstraction that is highly efficient for automated theorem provers, significantly reducing the complexity of state-related proofs.

Verification and Automation

F leverages the Z3 SMT solver to discharge proof obligations automatically. When automated solvers encounter complex quantifiers they cannot resolve, F allows users to intervene with manual "proof terms," functioning as a traditional proof assistant. To ensure logical consistency, the language enforces semantic termination for its pure core using a novel check based on well-founded ordering.

Evaluation and Results

The effectiveness of F was evaluated through several large-scale case studies, including the self-hosting F compiler (~20,500 lines of code) and a re-verification of key modules in miTLS, a verified implementation of the TLS-1.2 protocol.

The F* research and its associated artifacts were peer-reviewed and validated by the POPL Artifact Evaluation Committee.

Key results from these evaluations include:

  • Performance: The hyper-heap model achieved a 20x speedup in verification time for stateful benchmarks compared to traditional flat heap models.
  • Conciseness: In the miTLS case study, F* required approximately half the type annotations of its predecessors while proving more robust properties.
  • Automation: The combination of SMT and dependent types facilitated a "tactic-free" proof style, often resulting in more concise proofs than those found in Coq.

Conclusion

F demonstrates that it is possible to combine the power of dependent types with the automation of SMT solvers to verify real-world, effectful software. By treating effects as first-class citizens through Dijkstra monads and optimizing memory models for automation, F provides a scalable path toward secure and bug-free functional programming. Future work remains in developing a more robust internal tactic language and improving the transparency of SMT solver failures for end-users.

Summary updated

BibTeX
@inproceedings{swamy2016dependent,
  author = {Nikhil Swamy and Catalin Hritcu and Chantal Keller and Aseem Rastogi and Antoine Delignat-Lavaud and Simon Forest and Karthikeyan Bhargavan and Cédric Fournet and Pierre-Yves Strub and Markulf Kohlweiss and Jean Karim Zinzindohoue and Santiago Zanella-Béguelin},
  title = {{Dependent types and multi-monadic effects in F}},
  booktitle = {POPL},
  year = {2016},
  doi = {10.1145/2837614.2837655},
}
Figure