Representing Data Structures with Invariants in Haskell: The Cases of BST and AVL
Invariants are an essential aspect to take into account for the correct implementation of data structures and their operations. This paper explores how to encode and enforce invariants at type level in Haskell, using Binary Search Trees (BSTs) and AVL trees as case studies. This means the encoding of invariants at type level using advanced features of Haskell type system and their later verification by the type checker. We compare three approaches for the type-level encoding of invariants: fully externalist, externalist, and internalist, each offering a different balance between modularity, safety, and complexity. We also show how to systematically extract standard implementations from correct, invariant-based code.
Authors
- Marcos Viera (ORCID: https://orcid.org/0000-0003-2291-6151)
- Nuria Cobo-Losey Rodríguez
- Alberto Pardo (ORCID: https://orcid.org/0000-0003-3336-9755)
Institutions
- Universidad de la República de Uruguay (UY)
Publication Details
- Published
- 2025-10-09
- DOI
- https://doi.org/10.1145/3759538.3759652
- Primary Topic
- Logic, programming, and type systems
- Type
- article
- Field-Weighted Citation Impact
- 0.00