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

Safe Haskell | None
Language | Haskell2010

Language.Haskell.Meta.Utils

Contents

- Orphan instances

Description

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

Synopsis

- pretty :: Show a => a -> String
- conName :: Con -> Name
- dataDCons :: Dec -> [Con]
- decCons :: Dec -> [Con]
- decTyVars :: Dec -> [TyVarBndrVis]
- decName :: Dec -> Maybe Name
- foreignName :: Foreign -> Name
- cleanNames :: Data a => a -> a
- 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
- nameSpaceOf :: Name -> Maybe NameSpace
- (|$|) :: ExpQ -> ExpQ -> ExpQ
- (|.|) :: ExpQ -> ExpQ -> ExpQ
- (|->|) :: TypeQ -> TypeQ -> TypeQ
- unForall :: Type -> Type
- functionT :: [TypeQ] -> TypeQ
- mkVarT :: String -> TypeQ
- myNames :: [Name]
- renameThings :: (t1 -> t2 -> a1 -> (a2, t1, t2)) -> t1 -> t2 -> [a2] -> [a1] -> ([a2], t1, t2)
- 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])
- conTypes :: Con -> [Type]
- strictTypeTy :: StrictType -> Type
- varStrictTypeTy :: VarStrictType -> Type
- conToConType :: Type -> Con -> Type
- unwindT :: Type -> [Type]
- unwindE :: Exp -> [Exp]
- arityT :: Type -> Int
- typeToName :: Type -> Maybe Name
- recCName :: Con -> Maybe Name
- 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

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

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.

conName :: Con -> Name Source #

dataDCons :: Dec -> [Con] Source #

decCons :: Dec -> [Con] Source #

decTyVars :: Dec -> [TyVarBndrVis] Source #

decName :: Dec -> Maybe Name Source #

foreignName :: Foreign -> Name Source #

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

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

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

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

unsafeRunQ :: Q a -> a Source #

    unsafeRunQ = unsafePerformIO . runQ

nameToRawCodeStr :: Name -> String Source #

nameSpaceOf :: Name -> Maybe NameSpace Source #

Randomly useful.

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

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

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

unForall :: Type -> Type Source #

functionT :: [TypeQ] -> TypeQ Source #

mkVarT :: String -> TypeQ Source #

myNames :: [Name] Source #

Infinite list of names composed of lowercase letters

renameThings :: (t1 -> t2 -> a1 -> (a2, t1, t2)) -> t1 -> t2 -> [a2] -> [a1] -> ([a2], t1, t2) Source #

Generalisation of renameTs

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

renameT applied to a list of types

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

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 Source #

Remove qualification, etc.

applyT :: Type -> Type -> Type Source #

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

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

conTypes :: Con -> [Type] Source #

strictTypeTy :: StrictType -> Type Source #

varStrictTypeTy :: VarStrictType -> Type Source #

conToConType :: Type -> Con -> Type Source #

unwindT :: Type -> [Type] Source #

unwindE :: Exp -> [Exp] Source #

arityT :: Type -> Int Source #

The arity of a Type.

typeToName :: Type -> Maybe Name Source #

recCName :: Con -> Maybe Name Source #

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

fromTyConI :: Info -> Maybe Dec Source #

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

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

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

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 Source #

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

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

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

# Orphan instances

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