A new approach to generic functional programming
- 5 January 2000
- conference paper
- Published by Association for Computing Machinery (ACM)
- p. 119-132
- https://doi.org/10.1145/325694.325709
Abstract
This paper describes a new approach to generic functional programming, which allows us to define functions generically for all datatypes expressible in Haskell. A generic function is one that is defined by induction on the structure of types. Typical examples include pretty printers, parsers, and comparison functions. The advanced type system of Haskell presents a real challenge: datatypes may be parameterized not only by types but also by type constructors, type definitions may involve mutual recursion, and recursive calls of type constructors can be arbitrarily nested. We show that—despite this complexity—a generic function is uniquely defined by giving cases for primitive types and type constructors (such as disjoint unions and cartesian products). Given this information a generic function can be specialized to arbitrary Haskell datatypes. The key idea of the approach is to model types by terms of the simply typed λ-calculus augmented by a family of recursion operators. While conceptually simple, our approach places high demands on the type system: it requires polymorphic recursion, rank-n types, and a strong form of type constructor polymorphism. Finally, we point out connections to Haskell's class system and show that our approach generalizes type classes in some respects.Keywords
This publication has 23 references indexed in Scilit:
- Generalizing generalized triesJournal of Functional Programming, 2000
- de Bruijn notation as a nested datatypeJournal of Functional Programming, 1999
- Intensional polymorphism in type-erasure semanticsACM SIGPLAN Notices, 1998
- Encoding types in ML-like languagesACM SIGPLAN Notices, 1998
- Functorial MLJournal of Functional Programming, 1998
- Nested datatypesPublished by Springer Nature ,1998
- Type classes in HaskellACM Transactions on Programming Languages and Systems, 1996
- A system of constructor classes: overloading and implicit higher-order polymorphismJournal of Functional Programming, 1995
- Automatic generation and use of abstract structure operatorsACM Transactions on Programming Languages and Systems, 1991
- Fundamental properties of infinite treesTheoretical Computer Science, 1983