Generic programming allows you to write a function once, and use it many times at different types. Traditionally, generic functions are defined by induction on the structure of types. "Scrap your boilerplate" (SYB) is a radically different approach that dispatches on the structure of values. In previous work, we have shown how to reconcile both approaches using the concept of generic views: many generic functions can be based either on the classical sum-of-products view or on the view that underlies SYB, the so-called 'spine' view. One distinct advantage of the spine view is its generality: it is applicable to a large class of data types, including generalised algebraic data types. Its main weakness roots in the value-orientation: one can only define generic functions that consume data (show) but not ones that produce data (read). Furthermore, functions that abstract over type constructors (map, reduce) are out of reach. In this paper, we show how to overcome both limitations. The main technical contributions are the 'type spine' view and the 'lifted spine' view.
Andres Löh, 20.03.2006