Scrap Your Boilerplate (SYB) is a library for generic programming in Haskell. It is supported since the GHC >= 6.0 implementation of Haskell. Using this approach, you can write generic functions such as traversal schemes (e.g., everywhere and = everything=), as well as generic read, generic show and generic equality (i.e., gread, = gshow=, and = geq=). This approach is based on just a few primitives for type-safe cast and processing constructor applications.

It was originally developed by Ralf Lämmel and Simon Peyton Jones. Since then, many people have contributed with research relating to SYB or its applications.


Datatype-generic programming

Datatype-generic programming consists of defining functions on the structure of datatypes, rather than on a datatype itself. In this way, one can define functions that work for many different datatypes.

In SYB, the structure of datatypes is not directly exposed to the programmer. Instead, generic combinators are used to define the generic functions. These combinators are implemented using fundamental functions from the Data and Typeable classes.

Generic functions

Generic functions are usually written using methods from the Data class, which contains the generic combinators provided by SYB for this end.

Supported datatypes

Not all datatypes can be used immediately with generic functions, but adding support is very simple. All that is necessary is an instance of the datatype for the Data and Typeable classes. These are readily derivable by GHC, using the normal deriving mechanism. One can simply write:
data MyDataType = MyDataType deriving (Data, Typeable)


For API documentation, refer to the Haddock documentation.

You can also have a look at the original webpage, which contains many examples. The original SYB papers are also very informative:


SYB comes with GHC, but it is also available on Hackage. The version on Hackage is always the most up-to-date.


The source can be cloned from its repository using git:
git clone

You can also view the files online.

Handling the 6.10 base split

In the discussion towards the release of the 6.10 version of GHC, it was decided that SYB would be separated from the compiler itself. This allows for easier maintainability, since updating the library does not have to depend on updating the compiler. For the context, refer to the discussion in the mailing list (several threads: 1, 2, 3, 4). This splitting amounts to moving the Data.Generics modules from the base package into a new package called syb.

However, the Data class is very tightly coupled with the compiler due to the automatic generation of instances. Completely moving the entire SYB library from the base package would give a false sense of separation, since the methods of Data cannot be changed independently from the compiler. So, a separation was necessary: what depended on GHC stayed in base while the rest moved to syb.

The discussion on how to split SYB resulted in the following architecture:

Most of SYB was removed from base4. All the Data.Generics modules have been moved, but a new module, Data.Data, has been created. This module contains:
  • The entire contents of what was previously in Data.Generics.Basics. This is the Data class, all of its methods and associated utility functions and datatypes.
  • All of the instances that were previously in = Data.Generics.Instances=, except the instances for the following datatypes: DataType, TyCon, TypeRep, Handle, ThreadId, StablePtr, a -> b, IO a, ST s a, STM a, IORef a, TVar a, and MVar a. Those were moved to the syb package.

This new package contains the following modules:
  • Data.Generics.Basics This module is empty, and simply re-exports the new Data.Data module. It is provided for compatibility.
  • Data.Generics.Instances This module re-exports the instances from the new Data.Data module and also define the other instances that were previously in = Data.Generics.Instances=: DataType, TyCon, TypeRep, Handle, ThreadId, StablePtr, a -> b, IO a, ST s a, STM a, IORef a, TVar a, and MVar a. These instances were moved here because they were considered "dubious". What is meant by this is that it is not clear how these datatypes can be traversed. They might disappear or be changed in future releases of the library.
  • Data.Generics.Aliases, Data.Generics.Schemes, Data.Generics.Text, Data.Generics.Twins were moved directly from base and kept unchanged.
  • Data.Generics simply re-exports all the other modules for convenience (just like before).

This package is provided for compatibility reasons. Here, all SYB modules remain unchanged.

As a result, syb is now available as a package on Hackage.

Bugs & Support

To report bugs or suggest improvements, use the Google Code issue tracker for SYB.

For general concerns and questions, use the Generics mailing list.

Topic revision: r19 - 11 Nov 2013, JohanJeuring

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding UUCS? Send feedback