Skip to main content
QUICK REVIEW

[Paper Review] Dependently Typed Folds for Nested Data Types

Peng Fu, Peter Selinger|arXiv (Cornell University)|Jun 13, 2018
Logic, programming, and type systemsComputer Science13 references3 citations
TL;DR

This paper introduces dependently typed folds for nested data types, enabling total, formally verifiable programming via well-founded recursion in a dependently typed language. The approach generalizes traditional folds to nested types, yielding induction principles that support formal verification without requiring impredicative axioms or proof irrelevance.

ABSTRACT

We present an approach to develop folds for nested data types using dependent types. We call such folds $ extit{dependently typed folds}$, they have the following properties. (1) Dependently typed folds are defined by well-founded recursion and they can be defined in a total dependently typed language. (2) Dependently typed folds do not depend on maps, map functions and many terminating functions can be defined using dependently typed folds. (3) The induction principles for nested data types follow from the definitions of dependently typed folds and the programs defined by dependently typed folds can be formally verified. (4) Dependently typed folds exist for any nested data types and they can be specialized to the traditional $ extit{higher-order folds}$. Using various of examples, we show how to program and reason about dependently typed folds. We also show how to obtain dependently typed folds in general and how to specialize them to the corresponding higher-order folds.

Motivation & Objective

  • To address the lack of well-behaved folds for nested data types, which do not inherit the desirable properties of regular data type folds.
  • To develop a method for defining folds in a total dependently typed language that supports well-founded recursion and termination guarantees.
  • To derive induction principles from these folds to enable formal verification of programs involving nested data types.
  • To show that dependently typed folds can be specialized to traditional higher-order folds and support map-like functions without relying on general recursion.
  • To provide a foundation for formal reasoning about nested data types using only standard features of total dependently typed languages, avoiding impredicative Set or proof irrelevance.

Proposed method

  • Define dependently typed folds using well-founded recursion over nested data types, ensuring termination and totality.
  • Use large elimination to compute types by pattern-matching on values, enabling type-level computation from data-level recursion.
  • Generalize the fold type to support property-dependent types (p : T → Set), yielding induction principles for formal verification.
  • Construct the fold as a recursive function over the nested structure, where the recursive call is applied to the transformed substructure via a map-like transformation.
  • Specialize the dependently typed fold to recover standard higher-order folds by instantiating the type-level parameters appropriately.
  • Use Agda’s type system to encode the fold and its induction principle, demonstrating that proofs (e.g., of equivalence between map implementations) can be constructed using reflexivity and congruence.

Experimental results

Research questions

  • RQ1Can dependently typed folds be defined for arbitrary nested data types in a total, well-founded manner?
  • RQ2How can induction principles for nested data types be derived directly from fold definitions, enabling formal verification?
  • RQ3Can dependently typed folds be specialized to recover traditional higher-order folds and map functions?
  • RQ4What is the relationship between dependently typed folds and existing formalisms like generalized Mendler-style iterators or LNMIt?
  • RQ5Can formal proofs of program equivalence (e.g., between two map implementations) be constructed using the induction principles derived from dependently typed folds?

Key findings

  • Dependently typed folds are defined via well-founded recursion and are total in a dependently typed language like Agda.
  • The fold construction naturally gives rise to induction principles for nested data types, enabling formal verification of properties such as program equivalence.
  • The map function for nested data types can be defined using the dependently typed fold, and its correctness can be formally proven using the derived induction principle.
  • The approach avoids reliance on impredicative Set or proof irrelevance, unlike systems such as LNMIt, making it more foundational and compatible with standard Agda.
  • Dependently typed folds can be specialized to recover standard higher-order folds, showing that the new approach generalizes existing techniques.
  • The method supports Church encodings and indexed representations of nested data types through the fold’s type-level structure.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.