[Paper Review] Functor is to Lens as Applicative is to Biplate: Introducing Multiplate
This paper introduces Multiplate, a new generic programming abstraction in Haskell that generalizes Biplate and Compos to support mutually recursive data types with rank-3 polymorphism. It establishes a categorical isomorphism between the core types of Uniplate and Compos via coalgebras of a Cartesian store comonad and monoidal natural transformations, unifying their foundations and enabling a simpler, more powerful generic traversal system for complex data structures.
This paper gives two new categorical characterisations of lenses: one as a coalgebra of the store comonad, and the other as a monoidal natural transformation on a category of a certain class of coalgebras. The store comonad of the first characterisation can be generalized to a Cartesian store comonad, and the coalgebras of this Cartesian store comonad turn out to be exactly the Biplates of the Uniplate generic programming library. On the other hand, the monoidal natural transformations on functors can be generalized to work on a category of more specific coalgebras. This generalization turns out to be the type of compos from the Compos generic programming library. A theorem, originally conjectured by van Laarhoven, proves that these two generalizations are isomorphic, thus the core data types of the Uniplate and Compos libraries supporting generic program on single recursive types are the same. Both the Uniplate and Compos libraries generalize this core functionality to support mutually recursive types in different ways. This paper proposes a third extension to support mutually recursive data types that is as powerful as Compos and as easy to use as Uniplate. This proposal, called Multiplate, only requires rank 3 polymorphism in addition to the normal type class mechanism of Haskell.
Motivation & Objective
- To unify the categorical foundations of existing generic programming libraries like Uniplate and Compos.
- To generalize Biplate and Compos to support mutually recursive data types in a type-safe and composable way.
- To introduce a new abstraction, Multiplate, that combines the usability of Uniplate with the expressiveness of Compos.
- To prove that the core types of Uniplate and Compos are isomorphic via categorical characterizations of lenses and applicatives.
- To demonstrate that Multiplate requires only rank-3 polymorphism, making it accessible within standard Haskell type class mechanisms.
Proposed method
- Categorically characterizes lenses as coalgebras of the store comonad and generalizes this to a Cartesian store comonad.
- Identifies coalgebras of the Cartesian store comonad as the mathematical foundation of Biplate in Uniplate.
- Characterizes Compos' compos as monoidal natural transformations on a category of specific coalgebras.
- Proves an isomorphism between the two generalizations—Cartesian store comonad coalgebras and monoidal natural transformations—thereby unifying Uniplate and Compos.
- Proposes Multiplate as a new abstraction that generalizes both, using rank-3 polymorphism to support traversal over mutually recursive types.
- Uses categorical duality between Functor and Lens, and Applicative and Biplate, to guide the design and formalization of Multiplate.
Experimental results
Research questions
- RQ1Can the core types of Uniplate and Compos be shown to be categorically isomorphic?
- RQ2How can Biplate and Compos be generalized to support mutually recursive data types in a principled way?
- RQ3What categorical structure underlies the duality between Functor and Lens, and Applicative and Biplate?
- RQ4Can a new generic programming abstraction be constructed that combines the simplicity of Uniplate with the power of Compos?
- RQ5What type system features are necessary to express such a generalization, and can it be achieved with only rank-3 polymorphism?
Key findings
- The coalgebras of the Cartesian store comonad are isomorphic to the Biplate type, providing a categorical foundation for Uniplate's traversal mechanism.
- Monoidal natural transformations on a specific category of coalgebras are isomorphic to the Compos type, unifying its theoretical basis.
- The isomorphism between the two generalizations confirms that the core abstractions of Uniplate and Compos are categorically equivalent.
- Multiplate is proposed as a new generic programming abstraction that supports mutually recursive types with the same expressiveness as Compos and usability of Uniplate.
- The construction of Multiplate requires only rank-3 polymorphism, making it practical within standard Haskell type class systems.
- The paper establishes a formal duality: Functor is to Lens as Applicative is to Biplate, extending to Multiplate as the next generalization.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.