haskell-src-meta-0.8.0.1: Parse source to template-haskell abstract syntax.

Safe Haskell | None
Language | Haskell98

Language.Haskell.Meta.Utils

Contents

- Orphan instances

Description

This module is a staging ground for to-be-organized-and-merged-nicely code.

Synopsis

- cleanNames :: Data a => a -> a
- pretty :: Show a => a -> String
- pp :: (Data a, Ppr a) => a -> String
- ppDoc :: (Data a, Ppr a) => a -> Doc
- gpretty :: Data a => a -> String
- unsafeRunQ :: Q a -> a
- nameToRawCodeStr :: Name -> String
- (|$|) :: ExpQ -> ExpQ -> ExpQ
- (|.|) :: ExpQ -> ExpQ -> ExpQ
- (|->|) :: TypeQ -> TypeQ -> TypeQ
- unForall :: Type -> Type
- functionT :: [TypeQ] -> TypeQ
- mkVarT :: String -> TypeQ
- myNames :: [Name]
- renameThings :: (t2 -> t1 -> t -> (a, t2, t1)) -> t2 -> t1 -> [a] -> [t] -> ([a], t2, t1)
- renameTs :: [(Name, Name)] -> [Name] -> [Type] -> [Type] -> ([Type], [(Name, Name)], [Name])
- renameT :: [(Name, Name)] -> [Name] -> Type -> (Type, [(Name, Name)], [Name])
- normaliseName :: Name -> Name
- applyT :: Type -> Type -> Type
- substT :: [(Name, Type)] -> [Name] -> Type -> Type
- splitCon :: Con -> (Name, [Type])
- strictTypeTy :: StrictType -> Type
- varStrictTypeTy :: VarStrictType -> Type
- conTypes :: Con -> [Type]
- conToConType :: Type -> Con -> Type
- decCons :: Dec -> [Con]
- decTyVars :: Dec -> [TyVarBndr]
- decName :: Dec -> Maybe Name
- foreignName :: Foreign -> Name
- unwindT :: Type -> [Type]
- unwindE :: Exp -> [Exp]
- arityT :: Type -> Int
- typeToName :: Type -> Maybe Name
- nameSpaceOf :: Name -> Maybe NameSpace
- conName :: Con -> Name
- recCName :: Con -> Maybe Name
- dataDCons :: Dec -> [Con]
- fromDataConI :: Info -> Q (Maybe Exp)
- fromTyConI :: Info -> Maybe Dec
- mkFunD :: Name -> [Pat] -> Exp -> Dec
- mkClauseQ :: [PatQ] -> ExpQ -> ClauseQ
- toExpQ :: Lift a => (String -> Q a) -> String -> ExpQ
- toPatQ :: Show a => (String -> Q a) -> String -> PatQ
- showToPatQ :: Show a => a -> PatQ
- eitherQ :: (e -> String) -> Either e a -> Q a
- normalizeT :: Data a => a -> a

# Documentation

cleanNames :: Data a => a -> a #

pretty :: Show a => a -> String #

The type passed in must have a `Show` instance which produces a valid Haskell expression. Returns an empty `String` if this is not the case. This is not TH-specific, but useful in general.

pp :: (Data a, Ppr a) => a -> String #

ppDoc :: (Data a, Ppr a) => a -> Doc #

gpretty :: Data a => a -> String #

unsafeRunQ :: Q a -> a #

    unsafeRunQ = unsafePerformIO . runQ

nameToRawCodeStr :: Name -> String #

(|$|) :: ExpQ -> ExpQ -> ExpQ infixr 0 #

(|.|) :: ExpQ -> ExpQ -> ExpQ infixr 9 #

(|->|) :: TypeQ -> TypeQ -> TypeQ infixr 9 #

unForall :: Type -> Type #

functionT :: [TypeQ] -> TypeQ #

mkVarT :: String -> TypeQ #

myNames :: [Name] #

Infinite list of names composed of lowercase letters

renameThings :: (t2 -> t1 -> t -> (a, t2, t1)) -> t2 -> t1 -> [a] -> [t] -> ([a], t2, t1) #

Generalisation of renameTs

renameTs :: [(Name, Name)] -> [Name] -> [Type] -> [Type] -> ([Type], [(Name, Name)], [Name]) #

renameT applied to a list of types

renameT :: [(Name, Name)] -> [Name] -> Type -> (Type, [(Name, Name)], [Name]) #

Rename type variables in the Type according to the given association list. Normalise constructor names (remove qualification, etc.) If a name is not found in the association list, replace it with one from the fresh names list, and add this translation to the returned list. The fresh names list should be infinite; myNames is a good example.

normaliseName :: Name -> Name #

Remove qualification, etc.

applyT :: Type -> Type -> Type #

substT :: [(Name, Type)] -> [Name] -> Type -> Type #

splitCon :: Con -> (Name, [Type]) #

strictTypeTy :: StrictType -> Type #

varStrictTypeTy :: VarStrictType -> Type #

conTypes :: Con -> [Type] #

conToConType :: Type -> Con -> Type #

decCons :: Dec -> [Con] #

decTyVars :: Dec -> [TyVarBndr] #

decName :: Dec -> Maybe Name #

foreignName :: Foreign -> Name #

unwindT :: Type -> [Type] #

unwindE :: Exp -> [Exp] #

arityT :: Type -> Int #

The arity of a Type.

typeToName :: Type -> Maybe Name #

nameSpaceOf :: Name -> Maybe NameSpace #

Randomly useful.

conName :: Con -> Name #

recCName :: Con -> Maybe Name #

dataDCons :: Dec -> [Con] #

fromDataConI :: Info -> Q (Maybe Exp) #

fromTyConI :: Info -> Maybe Dec #

mkFunD :: Name -> [Pat] -> Exp -> Dec #

mkClauseQ :: [PatQ] -> ExpQ -> ClauseQ #

toExpQ :: Lift a => (String -> Q a) -> String -> ExpQ #

The strategy for producing QuasiQuoters which this datatype aims to facilitate is as follows. Given a collection of datatypes which make up the to-be-quasiquoted languages AST, make each type in this collection an instance of at least `Show` and `Lift`. Now, assuming `parsePat` and `parseExp`, both of type `String -> Q a` (where `a` is the top level type of the AST), are the pair of functions you wish to use for parsing in pattern and expression context respectively, put them inside a `Quoter` datatype and pass this to quasify.

toPatQ :: Show a => (String -> Q a) -> String -> PatQ #

showToPatQ :: Show a => a -> PatQ #

eitherQ :: (e -> String) -> Either e a -> Q a #

normalizeT :: Data a => a -> a #

# Orphan instances

Show ExpQ # |
Methods showsPrec :: Int -> ExpQ -> ShowS # show :: ExpQ -> String # showList :: [ExpQ] -> ShowS #
Show DecQ # |
Methods showsPrec :: Int -> DecQ -> ShowS # show :: DecQ -> String # showList :: [DecQ] -> ShowS #
Show TypeQ # |
Methods showsPrec :: Int -> TypeQ -> ShowS # show :: TypeQ -> String # showList :: [TypeQ] -> ShowS #
Show (Q [Dec]) # |
Methods showsPrec :: Int -> Q [Dec] -> ShowS # show :: Q [Dec] -> String # showList :: [Q [Dec]] -> ShowS #
Show (Q String) # |
Methods showsPrec :: Int -> Q String -> ShowS # show :: Q String -> String # showList :: [Q String] -> ShowS #
Show (Q Doc) # |
Methods showsPrec :: Int -> Q Doc -> ShowS # show :: Q Doc -> String # showList :: [Q Doc] -> ShowS #