Copyright | (c) 2010-2011 Patrick Bahr |
---|---|
License | BSD3 |
Maintainer | Patrick Bahr <paba@diku.dk> |
Stability | experimental |
Portability | non-portable (GHC Extensions) |
Safe Haskell | None |
Language | Haskell98 |
This module defines some utility functions for deriving instances for functor based type classes.
- abstractNewtypeQ :: Q Info -> Q Info
- abstractNewtype :: Info -> Info
- normalCon :: Con -> (Name, [StrictType])
- normalCon' :: Con -> (Name, [Type])
- normalConExp :: Con -> Q (Name, [Type])
- normalConStrExp :: Con -> Q (Name, [StrictType])
- abstractConType :: Con -> (Name, Int)
- tyVarBndrName :: TyVarBndr -> Name
- containsType :: Type -> Type -> Bool
- containsType' :: Type -> Type -> [Int]
- newNames :: Int -> String -> Q [Name]
- tupleTypes :: Int -> Int -> [Name]
- derive :: [Name -> Q [Dec]] -> [Name] -> Q [Dec]
- liftSumGen :: Name -> Name -> Name -> Q [Dec]
- findSig :: [Name] -> [Dec] -> Q (Maybe ([Name], [Name]))
Documentation
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.
normalCon' :: Con -> (Name, [Type]) Source
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
containsType :: Type -> Type -> Bool Source
containsType' :: Type -> Type -> [Int] Source
newNames :: Int -> String -> Q [Name] Source
This function provides a list (of the given length) of new names based on the given string.
tupleTypes :: Int -> Int -> [Name] Source
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.