Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Template Haskell utilities used to implement HMock.
Synopsis
- unappliedName :: Type -> Maybe Name
- tvName :: TyVarBndr flag -> Name
- bindVar :: Name -> TyVarBndr Specificity
- substTypeVar :: Name -> Type -> Type -> Type
- substTypeVars :: [(Name, Type)] -> Type -> Type
- splitType :: Type -> ([Name], Cxt, [Type], Type)
- freeTypeVars :: Type -> [Name]
- relevantContext :: Type -> ([Name], Cxt) -> ([Name], Cxt)
- constrainVars :: [TypeQ] -> [Name] -> CxtQ
- unifyTypes :: Type -> Type -> Q (Maybe [(Name, Type)])
- removeModNames :: Data a => a -> a
- hasPolyType :: Type -> Bool
- hasNestedPolyType :: Type -> Bool
- resolveInstance :: Name -> [Type] -> Q (Maybe Cxt)
- resolveInstanceType :: Type -> Q (Maybe Cxt)
- simplifyContext :: Cxt -> Q (Maybe Cxt)
- localizeMember :: Type -> Name -> Type -> Q Type
Documentation
unappliedName :: Type -> Maybe Name Source #
Gets the unapplied top-level name from a type application.
bindVar :: Name -> TyVarBndr Specificity Source #
Creates a TyVarBndr
for a plain variable without a kind annotation.
substTypeVars :: [(Name, Type)] -> Type -> Type Source #
Makes variable substitutions from the given table.
splitType :: Type -> ([Name], Cxt, [Type], Type) Source #
Splits a function type into a list of bound type vars, context, parameter types, and return value type.
relevantContext :: Type -> ([Name], Cxt) -> ([Name], Cxt) Source #
Culls the given binders and constraints to choose only those that apply to free variables in the given type.
unifyTypes :: Type -> Type -> Q (Maybe [(Name, Type)]) Source #
Attempts to unify the given types by constructing a table of substitutions for the variables of the left type that obtain the right one.
removeModNames :: Data a => a -> a Source #
Removes all module names from Name
s in the given value, so that it will
pretty-print more cleanly.
hasPolyType :: Type -> Bool Source #
Determines if this is a polytype, including top-level quantification.
hasNestedPolyType :: Type -> Bool Source #
Determines if there is a polytype nested anywhere in the given type. Top-level quantification doesn't count.
resolveInstanceType :: Type -> Q (Maybe Cxt) Source #
Attempts to produce sufficient constraints for the given Type
to be a
satisfied constraint. The type should be a class applied to its type
parameters.
Unlike simplifyContext
, this function always resolves the top-level
constraint, and returns Nothing
if it cannot do so.
simplifyContext :: Cxt -> Q (Maybe Cxt) Source #
Simplifies a context with complex types (requiring FlexibleContexts) to try to obtain one with all constraints applied to variables.
Should return Nothing if and only if the simplified contraint is unsatisfiable, which is the case if and only if it contains a component with no type variables.
localizeMember :: Type -> Name -> Type -> Q Type Source #
Remove instance context from a method.
Some GHC versions report class members including the instance context (for
example, show :: Show a => a -> String
, instead of show :: a -> String
).
This looks for the instance context, and substitutes if needed to eliminate
it.