Scrap your boilerplate
Authors:
Open Access
- 18 January 2003
- journal article
- Published by Association for Computing Machinery (ACM) in ACM SIGPLAN Notices
- Vol. 38 (3) , 26-37
Abstract
We describe a design pattern for writing programs that traverse data structures built from rich mutually-recursive data types. Such programs often have a great deal of "boilerplate" code that simply walks the structure, hiding a small amount of "real" code that constitutes the reason for the traversal.Our technique allows most of this boilerplate to be written once and for all, or even generated mechanically, leaving the programmer free to concentrate on the important part of the algorithm. These generic programs are much more adaptive when faced with data structure evolution because they contain many fewer lines of type-specific code.Our approach is simple to understand, reasonably efficient, and it handles all the data types found in conventional functional programming languages. It makes essential use of rank-2 polymorphism, an extension found in some implementations of Haskell. Further it relies on a simple type-safe cast operator.Keywords
This publication has 23 references indexed in Scilit:
- Template meta-programming for Haskell2002
- Higher-Order Intensional Type Analysis2002
- Haskell and XML1999
- Type dispatch for named hierarchical types1999
- Designing and Implementing Combinator Languages1999
- de Bruijn notation as a nested datatypeJournal of Functional Programming, 1999
- Polytypic programmingLecture Notes in Computer Science, 1996
- State in HaskellHigher-Order and Symbolic Computation, 1995
- Merging monads and folds for functional programmingLecture Notes in Computer Science, 1995
- Type reconstruction in finite rank fragments of the second-order λ-calculusInformation and Computation, 1992