template-haskell-util-0.1.0.1: Some utilities for template Haskell.

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Utils

Synopsis

Documentation

appExp :: [ExpQ] -> ExpQ Source

Apply a list of expression, [(+), 1, 2] to (+) 1 2

appConT :: [TypeQ] -> TypeQ Source

Apply a type constructor, convert [a, b, c] to a b c like appExp

curryType :: [TypeQ] -> TypeQ Source

> pprint $ appConT' (map ConT [''(,), ''Int , ''Bool])
"GHC.Tuple.(,) GHC.Types.Int GHC.Types.Bool"

|

convert [a, b, c] to a -> b -> c

genBT :: String -> Int -> Q ([TyVarBndr], [TypeQ]) Source

> pprint $ curryType' (map ConT [''Int , ''Int , ''Bool])
"GHC.Types.Int -> GHC.Types.Int -> GHC.Types.Bool"

|

Generate a list of type Bind and Type

genPE :: String -> Int -> Q ([PatQ], [ExpQ]) Source

> genBT' "a" 3
([PlainTV a1,PlainTV a2,PlainTV a3],[VarT a1,VarT a2,VarT a3])

|

Pattern and expression

genPE' :: String -> Int -> ([Pat], [Exp]) Source

appKinds :: [Kind] -> Kind Source

> genPE' "a" 3
([VarP a1,VarP a2,VarP a3],[VarE a1,VarE a2,VarE a3])

|

Apply a list of kinds

curryKind :: [Kind] -> Kind Source

convert [k1,k2,k3] to k1 -> k2 -> k3,like curryType

getTypeNames :: Type -> [Name] Source

get type Names recursively

getTVBName :: TyVarBndr -> Name Source

get type var bind name

getCompositeType :: Con -> [Name] Source

get all names recursively from a constructor