Language.Haskell.TH.ExpandSyns

th-expand-syns-0.4.3.0: Expands type synonyms in Template Haskell ASTs

Safe Haskell | None
Language | Haskell98

Language.Haskell.TH.ExpandSyns

Contents

- Expand synonyms
- Misc utilities

Synopsis

- expandSyns :: Type -> Q Type
- expandSynsWith :: SynonymExpansionSettings -> Type -> Q Type
- data SynonymExpansionSettings
- noWarnTypeFamilies :: SynonymExpansionSettings
- substInType :: (Name, Type) -> Type -> Type
- substInCon :: (Name, Type) -> Con -> Con
- evades :: Data t => [Name] -> t -> [Name]
- evade :: Data d => Name -> d -> Name

# Expand synonyms

expandSyns :: Type -> Q Type #

Calls `expandSynsWith` with the default settings.

expandSynsWith :: SynonymExpansionSettings -> Type -> Q Type #

Expands all type synonyms in the given type. Type families currently won't be expanded (but will be passed through).

data SynonymExpansionSettings #

Instances

Monoid SynonymExpansionSettings # | Default settings (`mempty`): Warn if type families are encountered. (The `mappend` is currently rather useless; the monoid instance is intended for additional settings in the future).
Methods mempty :: SynonymExpansionSettings # mappend :: SynonymExpansionSettings -> SynonymExpansionSettings -> SynonymExpansionSettings # mconcat :: [SynonymExpansionSettings] -> SynonymExpansionSettings #

noWarnTypeFamilies :: SynonymExpansionSettings #

Suppresses the warning that type families are unsupported.

# Misc utilities

substInType :: (Name, Type) -> Type -> Type #

Capture-free substitution

substInCon :: (Name, Type) -> Con -> Con #

Capture-free substitution

evades :: Data t => [Name] -> t -> [Name] #

Make a list of names (based on the first arg) such that every name in the result is distinct from every name in the second arg, and from the other results

evade :: Data d => Name -> d -> Name #

Make a name (based on the first arg) that's distinct from every name in the second arg

Example why this is necessary:

    type E x = forall y. Either x y

    ... expandSyns [t| forall y. y -> E y |]

The example as given may actually work correctly without any special capture-avoidance depending on how GHC handles the `y`s, but in any case, the input type to expandSyns may be an explicit AST using `mkName` to ensure a collision.