Some type class instances can be automatically derived from the structure of types. As a result, the Haskell language includes the "deriving" mechanism to automatic generates such instances for a small number of built-in type classes. In this paper, we present RepLib, a GHC library that enables a similar mechanism for arbitrary type classes. Users of RepLib can define the relationship between the structure of a datatype and the associated instance declaration by a normal Haskell functions that pattern-matches a representation type. Furthermore, operations defined in this manner are extensible-instances for specific types not defined by type structure may also be incorporated. Finally, this library also supports the definition of operations defined by parameterized types.In Section 7, we compare the capabilities of this proposal to existing work. For example, there are a number of ways to generically represent the structure of datatypes, and, more broadly, there are a number of ways to define type-indexed operations that do not rely on representation types. However, our view is that the success of any proposal relies on ease of adoption. Therefore, we have worked hard to identify a small set of mechanisms, implementable within the language of an existing Haskell compiler, that are, in our subjective view, useful for common situations and provide a programming model familiar to functional programmers.An initial release of RepLib is available for download 1 and is compilable with the Glasgow Haskell Compiler (GHC), version 6.4. This library is not portable. It requires many of the advanced features of GHC that are not found in Haskell 98: Higher-rank polymorphism [29], lexically-scoped type variables [31], Generalized Algebraic Datatypes (GADTs) [28], and undecidable instance declarations. Furthermore, Template Haskell [30] automates the definition of representations for new datatypes. However, all of these extensions are useful in their own respect.