Scrap your boilerplate

From HaskellWiki

Scrap Your Boilerplate (syb) is an infrastructure for generic programming in Haskell. (This should not be confused with the concept of "generic types" in Java, which in the Java context means parameterized types which allow you to specify the type of list elements and such things - a feature Haskell has had since its inception.)

In the current GHC implementation, it consists of a set of modules (Data.Generics and its submodules) and deriving support for the Data and Typeable classes from those modules.

1 Code snippets

1.1 ListifyWholeLists

This code snippet implements a variation on the listify function. listify recurses into every "node" in a datastructure, which is not so good if what you're searching for is lists (e.g. strings) and you don't want to pick up sublists (substrings, in the case of strings). This function does not recurse into lists of the type being searched for, avoiding that problem.

It illustrates the use of ShowS-style function composition as an alternative to recursive list concatenation - the latter is inefficient. It also illustrates how laziness automatically means that sublists of type [b] won't be examined, without any special effort required. Isn't laziness wonderful?