Safe Haskell | None |
---|---|
Language | Haskell2010 |
We can't warn about missing sigs as we have a group of decls in quasi-quotes that we're going to put in a class instance
Synopsis
- deriveTypeablePrim :: Name -> Int -> Q [Dec]
- type Constructor = (Name, Int, Maybe [Name], [Type])
- escape :: String -> String
- deriveDataPrim :: Name -> [Type] -> [Constructor] -> Q [Dec]
- deriveMinimalData :: Name -> Int -> Q [Dec]
- typeInfo :: Dec -> Q (Name, [Name], [Constructor])
- deriveOne :: Name -> Q [Dec]
- deriveOneDec :: Dec -> Q [Dec]
- deriveOneData :: Name -> Q [Dec]
- derive :: [Name] -> Q [Dec]
- deriveDec :: [Dec] -> Q [Dec]
- deriveData :: [Name] -> Q [Dec]
- deriveTypeable :: [Name] -> Q [Dec]
- deriveOneTypeable :: Name -> Q [Dec]
- deriveMinimalOne :: Name -> Q [Dec]
- deriveMinimal :: [Name] -> Q [Dec]
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
typeInfo :: Dec -> Q (Name, [Name], [Constructor]) Source #
@
instance Data NameSet where
gunfold _ _ _ = error ("gunfold not implemented")
toConstr x = error ("toConstr not implemented for " ++ show (typeOf x))
dataTypeOf x = error ("dataTypeOf not implemented for " ++ show (typeOf x))
gfoldl f z x = z x
@
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.