Lists that keep track of their reversal
The article discusses the nel package, a tiny library for describing non-empty lists in OCaml, which can serve as an error buffer for the Pidgin library in the context of applicative validation. The purpose of non-empty lists is to ensure that there is at least one element in the list, thanks to the semigroup nature of non-empty lists.
While the implementation is straightforward, it illustrates the desire for more invariants for common constructs like lists. The author explores Antonin Décimo's proposal to track the construction order in the type of a potential list, which could help enforce the presence of at least one element in the list. The author also presents a few ideas for implementing this concept in OCaml, using GADTs to encode constraints on type parameters through constructors.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.