Scrap your boilerplate: a practical approach to generic programming. Ralf Laemmel and Simon Peyton Jones. 12 pages, July 2002. Submitted to POPL 2003.
We describe a design pattern that 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 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.
For example, applying a function incS to all nodes of algebraic
datatype Company, would look something like
increase :: Float -> Company -> Company
increase k = everywhere (mkT (incS k))
Section 9.3 compares the work presented with other techniques including polytypic programing, generalized folds and visitors.
Posted to functional by Ehud Lamm on 8/3/02; 4:31:25 AM
|