Summary

This chapter started with a high-level discussion of the patterns of generic programming.

In the remainder of the chapter, we explored three variations of datatype-generic programming, that is, three techniques of parameterizing generic functions by data shape rather than by contents.

Underlying these varied approaches were some common threads:

  • To achieve generic functions, we need "generic data" (in the form of a universal type representation)
  • Datatype-generic programming mixes well with more rudimentary meta-programming (for example, when we autoderived Typeable instances in the process of writing generic functions)
  • using "shallow recursion" on a lower layer allows us to express all manner of recursive functions on the higher level

Generic ...

Get Haskell Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.