Copyright | Eric Mertens 2020 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe |
Language | Haskell2010 |
This module provides a backwards-compatible API for constructing and
manipulating TyVarBndr
s across multiple versions of the template-haskell
package.
Synopsis
- type TyVarBndr_ flag = TyVarBndr flag
- type TyVarBndrUnit = TyVarBndr ()
- type TyVarBndrSpec = TyVarBndr Specificity
- type TyVarBndrVis = TyVarBndr_ BndrVis
- data Specificity
- type BndrVis = ()
- pattern BndrReq :: BndrVis
- pattern BndrInvis :: BndrVis
- class DefaultBndrFlag flag where
- defaultBndrFlag :: flag
- plainTVFlag :: Name -> flag -> TyVarBndr_ flag
- kindedTVFlag :: Name -> flag -> Kind -> TyVarBndr_ flag
- plainTV :: Name -> TyVarBndr ()
- kindedTV :: Name -> Kind -> TyVarBndr ()
- plainTVInferred :: Name -> TyVarBndrSpec
- plainTVSpecified :: Name -> TyVarBndrSpec
- kindedTVInferred :: Name -> Kind -> TyVarBndrSpec
- kindedTVSpecified :: Name -> Kind -> TyVarBndrSpec
- plainTVReq :: Name -> TyVarBndrVis
- plainTVInvis :: Name -> TyVarBndrVis
- kindedTVReq :: Name -> Kind -> TyVarBndrVis
- kindedTVInvis :: Name -> Kind -> TyVarBndrVis
- inferredSpec :: Specificity
- specifiedSpec :: Specificity
- bndrReq :: BndrVis
- bndrInvis :: BndrVis
- elimTV :: (Name -> r) -> (Name -> Kind -> r) -> TyVarBndr_ flag -> r
- elimTVFlag :: (Name -> flag -> r) -> (Name -> flag -> Kind -> r) -> TyVarBndr_ flag -> r
- mapTV :: (Name -> Name) -> (flag -> flag') -> (Kind -> Kind) -> TyVarBndr_ flag -> TyVarBndr_ flag'
- mapTVName :: (Name -> Name) -> TyVarBndr_ flag -> TyVarBndr_ flag
- mapTVFlag :: (flag -> flag') -> TyVarBndr_ flag -> TyVarBndr_ flag'
- mapTVKind :: (Kind -> Kind) -> TyVarBndr_ flag -> TyVarBndr_ flag
- traverseTV :: Applicative f => (Name -> f Name) -> (flag -> f flag') -> (Kind -> f Kind) -> TyVarBndr_ flag -> f (TyVarBndr_ flag')
- traverseTVName :: Functor f => (Name -> f Name) -> TyVarBndr_ flag -> f (TyVarBndr_ flag)
- traverseTVFlag :: Applicative f => (flag -> f flag') -> TyVarBndr_ flag -> f (TyVarBndr_ flag')
- traverseTVKind :: Applicative f => (Kind -> f Kind) -> TyVarBndr_ flag -> f (TyVarBndr_ flag)
- mapMTV :: Monad m => (Name -> m Name) -> (flag -> m flag') -> (Kind -> m Kind) -> TyVarBndr_ flag -> m (TyVarBndr_ flag')
- mapMTVName :: Monad m => (Name -> m Name) -> TyVarBndr_ flag -> m (TyVarBndr_ flag)
- mapMTVFlag :: Monad m => (flag -> m flag') -> TyVarBndr_ flag -> m (TyVarBndr_ flag')
- mapMTVKind :: Monad m => (Kind -> m Kind) -> TyVarBndr_ flag -> m (TyVarBndr_ flag)
- changeTVFlags :: newFlag -> [TyVarBndr_ oldFlag] -> [TyVarBndr_ newFlag]
- tvName :: TyVarBndr_ flag -> Name
- tvKind :: TyVarBndr_ flag -> Kind
- tvFlag :: TyVarBndr_ flag -> flag
TyVarBndr
-related types
type TyVarBndr_ flag = TyVarBndr flag Source #
type TyVarBndrUnit = TyVarBndr () #
type TyVarBndrSpec = TyVarBndr Specificity #
type TyVarBndrVis = TyVarBndr_ BndrVis Source #
data Specificity #
Instances
pattern BndrInvis :: BndrVis Source #
Because pre-9.8 GHCs do not support invisible binders in type-level declarations, this compatibility shim is defined in a somewhat unusual way:
- As a pattern,
BndrInvis
will never match on pre-9.8 GHCs. That way, if you write pattern matches like this:
case flag ofBndrInvis
-> ...BndrVis
-> ...
Then the first branch will never be taken on pre-9.8 GHCs.
BndrInvis
is a unidirectional pattern synonym on pre-9.8 GHCs, so it cannot be used as an expression on these GHC versions. This is done in an effort to avoid pitfalls that could occur ifBndrInvis
were defined like so:
pattern BndrInvis
= ()
If this were the definition, then a user could write code involving
BndrInvis
that would construct an invisible type-level binder on GHC 9.8
or later, but a visible type-level binder on older GHCs! This would be
disastrous, so we prevent the user from doing such a thing.
class DefaultBndrFlag flag where Source #
A class characterizing reasonable default values for various TyVarBndr
flag
types.
defaultBndrFlag :: flag Source #
Instances
DefaultBndrFlag Specificity Source # | |
Defined in Language.Haskell.TH.Datatype.TyVarBndr | |
DefaultBndrFlag () Source # | |
Defined in Language.Haskell.TH.Datatype.TyVarBndr defaultBndrFlag :: () Source # |
Constructing TyVarBndr
s
flag
-polymorphic
plainTVFlag :: Name -> flag -> TyVarBndr_ flag Source #
Construct a PlainTV
with the given flag
.
kindedTVFlag :: Name -> flag -> Kind -> TyVarBndr_ flag Source #
Construct a KindedTV
with the given flag
.
TyVarBndrUnit
TyVarBndrSpec
plainTVInferred :: Name -> TyVarBndrSpec Source #
Construct a PlainTV
with an InferredSpec
.
plainTVSpecified :: Name -> TyVarBndrSpec Source #
Construct a PlainTV
with a SpecifiedSpec
.
kindedTVInferred :: Name -> Kind -> TyVarBndrSpec Source #
Construct a KindedTV
with an InferredSpec
.
kindedTVSpecified :: Name -> Kind -> TyVarBndrSpec Source #
Construct a KindedTV
with a SpecifiedSpec
.
TyVarBndrVis
plainTVReq :: Name -> TyVarBndrVis Source #
plainTVInvis :: Name -> TyVarBndrVis Source #
kindedTVReq :: Name -> Kind -> TyVarBndrVis Source #
kindedTVInvis :: Name -> Kind -> TyVarBndrVis Source #
Constructing Specificity
Constructing BndrVis
Modifying TyVarBndr
s
elimTVFlag :: (Name -> flag -> r) -> (Name -> flag -> Kind -> r) -> TyVarBndr_ flag -> r Source #
mapTV :: (Name -> Name) -> (flag -> flag') -> (Kind -> Kind) -> TyVarBndr_ flag -> TyVarBndr_ flag' Source #
Map over the components of a TyVarBndr
.
mapTVName :: (Name -> Name) -> TyVarBndr_ flag -> TyVarBndr_ flag Source #
mapTVFlag :: (flag -> flag') -> TyVarBndr_ flag -> TyVarBndr_ flag' Source #
Map over the flag
of a TyVarBndr
.
mapTVKind :: (Kind -> Kind) -> TyVarBndr_ flag -> TyVarBndr_ flag Source #
traverseTV :: Applicative f => (Name -> f Name) -> (flag -> f flag') -> (Kind -> f Kind) -> TyVarBndr_ flag -> f (TyVarBndr_ flag') Source #
Traverse the components of a TyVarBndr
.
traverseTVName :: Functor f => (Name -> f Name) -> TyVarBndr_ flag -> f (TyVarBndr_ flag) Source #
traverseTVFlag :: Applicative f => (flag -> f flag') -> TyVarBndr_ flag -> f (TyVarBndr_ flag') Source #
Traverse the flag
of a TyVarBndr
.
traverseTVKind :: Applicative f => (Kind -> f Kind) -> TyVarBndr_ flag -> f (TyVarBndr_ flag) Source #
mapMTV :: Monad m => (Name -> m Name) -> (flag -> m flag') -> (Kind -> m Kind) -> TyVarBndr_ flag -> m (TyVarBndr_ flag') Source #
Map over the components of a TyVarBndr
in a monadic fashion.
This is the same as traverseTV
, but with a Monad
constraint. This is
mainly useful for use with old versions of base
where Applicative
was
not a superclass of Monad
.
mapMTVName :: Monad m => (Name -> m Name) -> TyVarBndr_ flag -> m (TyVarBndr_ flag) Source #
Map over the Name
of a TyVarBndr
in a monadic fashion.
This is the same as traverseTVName
, but with a Monad
constraint. This is
mainly useful for use with old versions of base
where Applicative
was
not a superclass of Monad
.
mapMTVFlag :: Monad m => (flag -> m flag') -> TyVarBndr_ flag -> m (TyVarBndr_ flag') Source #
Map over the flag
of a TyVarBndr
in a monadic fashion.
This is the same as traverseTVFlag
, but with a Monad
constraint. This is
mainly useful for use with old versions of base
where Applicative
was
not a superclass of Monad
.
mapMTVKind :: Monad m => (Kind -> m Kind) -> TyVarBndr_ flag -> m (TyVarBndr_ flag) Source #
Map over the Kind
of a TyVarBndr
in a monadic fashion.
This is the same as traverseTVKind
, but with a Monad
constraint. This is
mainly useful for use with old versions of base
where Applicative
was
not a superclass of Monad
.
changeTVFlags :: newFlag -> [TyVarBndr_ oldFlag] -> [TyVarBndr_ newFlag] Source #
Set the flag in a list of TyVarBndr
s. This is often useful in contexts
where one needs to re-use a list of TyVarBndr
s from one flag setting to
another flag setting. For example, in order to re-use the TyVarBndr
s bound
by a DataD
in a ForallT
, one can do the following:
case x ofDataD
_ _ tvbs _ _ _ ->ForallT
(changeTVFlags
SpecifiedSpec
tvbs) ...
Properties of TyVarBndr
s
tvName :: TyVarBndr_ flag -> Name Source #
Extract the type variable name from a TyVarBndr
, ignoring the
kind signature if one exists.
tvKind :: TyVarBndr_ flag -> Kind Source #