th-abstraction-0.4.3.0: Nicer interface for reified information about data types

Copyright | Eric Mertens 2020
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | Safe
Language | Haskell2010

Language.Haskell.TH.Datatype.TyVarBndr

Contents

- `TyVarBndr`-related types
- Constructing `TyVarBndr`s
  - `flag`-polymorphic
  - `TyVarBndrUnit`
  - `TyVarBndrSpec`
- Constructing `Specificity`
- Modifying `TyVarBndr`s
- Properties of `TyVarBndr`s

Description

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
- type TyVarBndrUnit = TyVarBndr
- type TyVarBndrSpec = TyVarBndr
- data Specificity
  - = SpecifiedSpec
  - | InferredSpec
- 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
- inferredSpec :: Specificity
- specifiedSpec :: Specificity
- elimTV :: (Name -> r) -> (Name -> 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

# `TyVarBndr`-related types

type TyVarBndr_ flag = TyVarBndr #

A type synonym for `TyVarBndr`. This is the recommended way to refer to `TyVarBndr`s if you wish to achieve backwards compatibility with older versions of `template-haskell`, where `TyVarBndr` lacked a `flag` type parameter representing its specificity (if it has one).

type TyVarBndrUnit = TyVarBndr #

A `TyVarBndr` where the specificity is irrelevant. This is used for `TyVarBndr`s that do not interact with visible type application.

type TyVarBndrSpec = TyVarBndr #

A `TyVarBndr` with an explicit `Specificity`. This is used for `TyVarBndr`s that interact with visible type application.

data Specificity #

Determines how a `TyVarBndr` interacts with visible type application.

Constructors

SpecifiedSpec | `a`. Eligible for visible type application.
InferredSpec | `{a}`. Not eligible for visible type application.

#### Instances

Instances details

Eq Specificity # |
Instance details Defined in Language.Haskell.TH.Datatype.TyVarBndr Methods (==) :: Specificity -> Specificity -> Bool # (/=) :: Specificity -> Specificity -> Bool #
Data Specificity # |
Instance details Defined in Language.Haskell.TH.Datatype.TyVarBndr Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Specificity -> c Specificity # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Specificity # toConstr :: Specificity -> Constr # dataTypeOf :: Specificity -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Specificity) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Specificity) # gmapT :: (forall b. Data b => b -> b) -> Specificity -> Specificity # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Specificity -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Specificity -> r # gmapQ :: (forall d. Data d => d -> u) -> Specificity -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Specificity -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Specificity -> m Specificity # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Specificity -> m Specificity # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Specificity -> m Specificity #
Ord Specificity # |
Instance details Defined in Language.Haskell.TH.Datatype.TyVarBndr Methods compare :: Specificity -> Specificity -> Ordering # (<) :: Specificity -> Specificity -> Bool # (<=) :: Specificity -> Specificity -> Bool # (>) :: Specificity -> Specificity -> Bool # (>=) :: Specificity -> Specificity -> Bool # max :: Specificity -> Specificity -> Specificity # min :: Specificity -> Specificity -> Specificity #
Show Specificity # |
Instance details Defined in Language.Haskell.TH.Datatype.TyVarBndr Methods showsPrec :: Int -> Specificity -> ShowS # show :: Specificity -> String # showList :: [Specificity] -> ShowS #
Generic Specificity # |
Instance details Defined in Language.Haskell.TH.Datatype.TyVarBndr Associated Types type Rep Specificity :: Type -> Type # Methods from :: Specificity -> Rep Specificity x # to :: Rep Specificity x -> Specificity #
type Rep Specificity # |
Instance details Defined in Language.Haskell.TH.Datatype.TyVarBndr type Rep Specificity = D1 ('MetaData "Specificity" "Language.Haskell.TH.Datatype.TyVarBndr" "th-abstraction-0.4.3.0-2bR6PShrhI5Ky9S2fwQwaC" 'False) (C1 ('MetaCons "SpecifiedSpec" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InferredSpec" 'PrefixI 'False) (U1 :: Type -> Type))

# Constructing `TyVarBndr`s

## `flag`-polymorphic

plainTVFlag :: Name -> flag -> TyVarBndr_ flag #

Construct a `PlainTV` with the given `flag`.

kindedTVFlag :: Name -> flag -> Kind -> TyVarBndr_ flag #

Construct a `KindedTV` with the given `flag`.

## `TyVarBndrUnit`

plainTV :: Name -> TyVarBndr #

kindedTV :: Name -> Kind -> TyVarBndr #

## `TyVarBndrSpec`

plainTVInferred :: Name -> TyVarBndrSpec #

Construct a `PlainTV` with an `InferredSpec`.

plainTVSpecified :: Name -> TyVarBndrSpec #

Construct a `PlainTV` with a `SpecifiedSpec`.

kindedTVInferred :: Name -> Kind -> TyVarBndrSpec #

Construct a `KindedTV` with an `InferredSpec`.

kindedTVSpecified :: Name -> Kind -> TyVarBndrSpec #

Construct a `KindedTV` with a `SpecifiedSpec`.

# Constructing `Specificity`

inferredSpec :: Specificity #

specifiedSpec :: Specificity #

# Modifying `TyVarBndr`s

elimTV :: (Name -> r) -> (Name -> Kind -> r) -> TyVarBndr_ flag -> r #

Case analysis for a `TyVarBndr`. If the value is a ``PlainTV` n _`, apply the first function to `n`; if it is ``KindedTV` n _ k`, apply the second function to `n` and `k`.

mapTV :: (Name -> Name) -> (flag -> flag') -> (Kind -> Kind) -> TyVarBndr_ flag -> TyVarBndr_ flag' #

Map over the components of a `TyVarBndr`.

mapTVName :: (Name -> Name) -> TyVarBndr_ flag -> TyVarBndr_ flag #

Map over the `Name` of a `TyVarBndr`.

mapTVFlag :: (flag -> flag') -> TyVarBndr_ flag -> TyVarBndr_ flag' #

Map over the `flag` of a `TyVarBndr`.

mapTVKind :: (Kind -> Kind) -> TyVarBndr_ flag -> TyVarBndr_ flag #

Map over the `Kind` of a `TyVarBndr`.

traverseTV :: Applicative f => (Name -> f Name) -> (flag -> f flag') -> (Kind -> f Kind) -> TyVarBndr_ flag -> f (TyVarBndr_ flag') #

Traverse the components of a `TyVarBndr`.

traverseTVName :: Functor f => (Name -> f Name) -> TyVarBndr_ flag -> f (TyVarBndr_ flag) #

Traverse the `Name` of a `TyVarBndr`.

traverseTVFlag :: Applicative f => (flag -> f flag') -> TyVarBndr_ flag -> f (TyVarBndr_ flag') #

Traverse the `flag` of a `TyVarBndr`.

traverseTVKind :: Applicative f => (Kind -> f Kind) -> TyVarBndr_ flag -> f (TyVarBndr_ flag) #

Traverse the `Kind` of a `TyVarBndr`.

mapMTV :: Monad m => (Name -> m Name) -> (flag -> m flag') -> (Kind -> m Kind) -> TyVarBndr_ flag -> m (TyVarBndr_ flag') #

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

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') #

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

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

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 of
      DataD _ _ tvbs _ _ _ ->
        ForallT (changeTVFlags SpecifiedSpec tvbs) ...

# Properties of `TyVarBndr`s

tvName :: TyVarBndr_ flag -> Name #

Extract the type variable name from a `TyVarBndr`, ignoring the kind signature if one exists.

tvKind :: TyVarBndr_ flag -> Kind #

Extract the kind from a `TyVarBndr`. Assumes `PlainTV` has kind `*`.