compdata-0.9: Compositional Data Types

Copyright(c) 2010-2011 Patrick Bahr
MaintainerPatrick Bahr <>
Portabilitynon-portable (GHC Extensions)
Safe HaskellNone



This module defines some utility functions for deriving instances for functor based type classes.



abstractNewtypeQ :: Q Info -> Q Info Source

This is the Q-lifted version of 'abstractNewtypeQ.

abstractNewtype :: Info -> Info Source

This function abstracts away newtype declaration, it turns them into data declarations.

normalCon :: Con -> (Name, [StrictType]) Source

This function provides the name and the arity of the given data constructor.

normalConExp :: Con -> Q (Name, [Type]) Source

Same as normalCon' but expands type synonyms.

normalConStrExp :: Con -> Q (Name, [StrictType]) Source

Same as normalConExp' but retains strictness annotations.

abstractConType :: Con -> (Name, Int) Source

This function provides the name and the arity of the given data constructor.

tyVarBndrName :: TyVarBndr -> Name Source

This function returns the name of a bound type variable

newNames :: Int -> String -> Q [Name] Source

This function provides a list (of the given length) of new names based on the given string.

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

Helper function for generating a list of instances for a list of named signatures. For example, in order to derive instances Functor and ShowF for a signature Exp, use derive as follows (requires Template Haskell):

$(derive [makeFunctor, makeShowF] [''Exp])

liftSumGen :: Name -> Name -> Name -> Q [Dec] Source

This function lifts type class instances over sums ofsignatures. To this end it assumes that it contains only methods with types of the form f t1 .. tn -> t where f is the signature that is used to construct sums. Since this function is generic it assumes as its first argument the name of the function that is used to lift methods over sums i.e. a function of type

(f t1 .. tn -> t) -> (g t1 .. tn -> t) -> ((f :+: g) t1 .. tn -> t)

where :+: is the sum type constructor. The second argument to this function is expected to be the name of that constructor. The last argument is the name of the class whose instances should be lifted over sums.

findSig :: [Name] -> [Dec] -> Q (Maybe ([Name], [Name])) Source