template-haskell-util-0.1.0.2: 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

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

curryType :: [TypeQ] -> TypeQ Source

convert [a, b, c] to a -> b -> c
> pprint $ curryType' (map ConT [''Int , ''Int , ''Bool])
"GHC.Types.Int -> GHC.Types.Int -> GHC.Types.Bool"

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

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

Generate a list of type Bind and Type

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

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

Related patterns and expressions

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

appKinds :: [Kind] -> Kind Source

Apply a list of kinds, like appConT

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

getConName :: Con -> Name Source

Get name from constructors

seqTuple2 :: (Q a, Q b) -> Q (a, b) Source

sequence-like functons on tuples

seqTuple3 :: (Q a, Q b, Q c) -> Q (a, b, c) Source

seqTuple4 :: (Q a, Q b, Q c, Q d) -> Q (a, b, c, d) Source

rename' :: Name -> (String -> String) -> Name Source

Rename a Name

nameToExp Source

Arguments

:: (String -> String)

Function to change name.

-> Name 
-> Q Exp 
data Foo = Foo { foo :: Int }
> $(nameToExp (++"1") 'foo)
"foo1"       

printQ :: Show a => Q a -> IO () Source

Print AST