syb-with-class-0.6.1.10: Scrap Your Boilerplate With Class

Safe HaskellNone
LanguageHaskell98

Data.Generics.SYB.WithClass.Derive

Synopsis

Documentation

deriveTypeablePrim :: Name -> Int -> Q [Dec] Source #

Takes the name of an algebraic data type, the number of type parameters it has and creates a Typeable instance for it.

deriveDataPrim :: Name -> [Type] -> [Constructor] -> Q [Dec] Source #

Takes a name of a algebraic data type, the number of parameters it has and a list of constructor pairs. Each one of these constructor pairs consists of a constructor name and the number of type parameters it has. The function returns an automatically generated instance declaration for the Data class.

Doesn't do gunfold, dataCast1 or dataCast2

deriveOne :: Name -> Q [Dec] Source #

Derives the Data and Typeable instances for a single given data type.

derive :: [Name] -> Q [Dec] Source #

Derives Data and Typeable instances for a list of data types. Order is irrelevant. This should be used in favour of deriveOne since Data and Typeable instances can often depend on other Data and Typeable instances - e.g. if you are deriving a large, mutually recursive data type. If you splice the derived instances in one by one you will need to do it in depedency order which is difficult in most cases and impossible in the mutually recursive case. It is better to bring all the instances into scope at once.

e.g. if data Foo = Foo Int is declared in an imported module then $(derive [''Foo]) will derive the instances for it

deriveMinimalOne :: Name -> Q [Dec] Source #

This function is much like deriveOne except that it brings into scope an instance of Data with minimal definitions. gfoldl will essentially leave a data structure untouched while gunfoldl, toConstr and dataTypeOf will yield errors.

This function is useful when you are certain that you will never wish to transform a particular data type. For instance you may be transforming another data type that contains other data types, some of which you wish to transform (perhaps recursively) and some which you just wish to return unchanged.

Sometimes you will be forced to use deriveMinimalOne because you do not have access to the contructors of the data type (perhaps because it is an Abstract Data Type). However, should the interface to the ADT be sufficiently rich it is possible to define you're own Data and Typeable instances.