th-abstraction-0.7.1.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`
  - `TyVarBndrVis`
- Constructing `Specificity`
- Constructing `BndrVis`
- 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 flag
- type TyVarBndrUnit = TyVarBndr ()
- type TyVarBndrSpec = TyVarBndr Specificity
- type TyVarBndrVis = TyVarBndr BndrVis
- data Specificity
  - = SpecifiedSpec
  - | InferredSpec
- data BndrVis
  - = BndrReq
  - | BndrInvis
- class DefaultBndrFlag flag where
  - defaultBndrFlag :: flag
- plainTVFlag :: Name -> flag -> TyVarBndr_ flag
- kindedTVFlag :: Name -> flag -> Kind -> TyVarBndr_ flag
- plainTV :: DefaultBndrFlag flag => Name -> TyVarBndr flag
- kindedTV :: DefaultBndrFlag flag => Name -> Kind -> TyVarBndr flag
- 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 #

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 (if it has one).

type TyVarBndrUnit = TyVarBndr () Source #

type TyVarBndrSpec = TyVarBndr Specificity Source #

type TyVarBndrVis = TyVarBndr BndrVis Source #

data Specificity Source #

Constructors

SpecifiedSpec

    a

InferredSpec

    {a}

#### Instances

Instances details

Data Specificity |

Instance details

Defined in Language.Haskell.TH.Syntax

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Specificity -> c Specificity Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Specificity Source #

toConstr :: Specificity -> Constr Source #

dataTypeOf :: Specificity -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Specificity) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Specificity) Source #

gmapT :: (forall b. Data b => b -> b) -> Specificity -> Specificity Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Specificity -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Specificity -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Specificity -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Specificity -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Specificity -> m Specificity Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Specificity -> m Specificity Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Specificity -> m Specificity Source #

Generic Specificity |

Instance details

Defined in Language.Haskell.TH.Syntax

Associated Types

type Rep Specificity |
Instance details Defined in Language.Haskell.TH.Syntax type Rep Specificity = D1 ('MetaData "Specificity" "Language.Haskell.TH.Syntax" "template-haskell" 'False) (C1 ('MetaCons "SpecifiedSpec" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InferredSpec" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: Specificity -> Rep Specificity x Source #

to :: Rep Specificity x -> Specificity Source #

Show Specificity |
Instance details Defined in Language.Haskell.TH.Syntax Methods showsPrec :: Int -> Specificity -> ShowS Source # show :: Specificity -> String Source # showList :: [Specificity] -> ShowS Source #
Eq Specificity |
Instance details Defined in Language.Haskell.TH.Syntax Methods (==) :: Specificity -> Specificity -> Bool Source # (/=) :: Specificity -> Specificity -> Bool Source #
Ord Specificity |

Instance details

Defined in Language.Haskell.TH.Syntax

Methods

compare :: Specificity -> Specificity -> Ordering Source #

(<) :: Specificity -> Specificity -> Bool Source #

(<=) :: Specificity -> Specificity -> Bool Source #

(>) :: Specificity -> Specificity -> Bool Source #

(>=) :: Specificity -> Specificity -> Bool Source #

max :: Specificity -> Specificity -> Specificity Source #

min :: Specificity -> Specificity -> Specificity Source #

DefaultBndrFlag Specificity |
Instance details Defined in Language.Haskell.TH.Lib Methods defaultBndrFlag :: Specificity Source #
PprFlag Specificity |
Instance details Defined in Language.Haskell.TH.Ppr Methods pprTyVarBndr :: TyVarBndr Specificity -> Doc Source #
type Rep Specificity |
Instance details Defined in Language.Haskell.TH.Syntax type Rep Specificity = D1 ('MetaData "Specificity" "Language.Haskell.TH.Syntax" "template-haskell" 'False) (C1 ('MetaCons "SpecifiedSpec" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "InferredSpec" 'PrefixI 'False) (U1 :: Type -> Type))

data BndrVis Source #

Constructors

BndrReq

    a

BndrInvis

    @a

#### Instances

Instances details

Data BndrVis |

Instance details

Defined in Language.Haskell.TH.Syntax

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BndrVis -> c BndrVis Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c BndrVis Source #

toConstr :: BndrVis -> Constr Source #

dataTypeOf :: BndrVis -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c BndrVis) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BndrVis) Source #

gmapT :: (forall b. Data b => b -> b) -> BndrVis -> BndrVis Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BndrVis -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BndrVis -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> BndrVis -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> BndrVis -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BndrVis -> m BndrVis Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BndrVis -> m BndrVis Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BndrVis -> m BndrVis Source #

Generic BndrVis |

Instance details

Defined in Language.Haskell.TH.Syntax

Associated Types

type Rep BndrVis |
Instance details Defined in Language.Haskell.TH.Syntax type Rep BndrVis = D1 ('MetaData "BndrVis" "Language.Haskell.TH.Syntax" "template-haskell" 'False) (C1 ('MetaCons "BndrReq" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BndrInvis" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: BndrVis -> Rep BndrVis x Source #

to :: Rep BndrVis x -> BndrVis Source #

Show BndrVis |
Instance details Defined in Language.Haskell.TH.Syntax Methods showsPrec :: Int -> BndrVis -> ShowS Source # show :: BndrVis -> String Source # showList :: [BndrVis] -> ShowS Source #
Eq BndrVis |
Instance details Defined in Language.Haskell.TH.Syntax Methods (==) :: BndrVis -> BndrVis -> Bool Source # (/=) :: BndrVis -> BndrVis -> Bool Source #
Ord BndrVis |
Instance details Defined in Language.Haskell.TH.Syntax Methods compare :: BndrVis -> BndrVis -> Ordering Source # (<) :: BndrVis -> BndrVis -> Bool Source # (<=) :: BndrVis -> BndrVis -> Bool Source # (>) :: BndrVis -> BndrVis -> Bool Source # (>=) :: BndrVis -> BndrVis -> Bool Source # max :: BndrVis -> BndrVis -> BndrVis Source # min :: BndrVis -> BndrVis -> BndrVis Source #
DefaultBndrFlag BndrVis |
Instance details Defined in Language.Haskell.TH.Lib Methods defaultBndrFlag :: BndrVis Source #
PprFlag BndrVis |
Instance details Defined in Language.Haskell.TH.Ppr Methods pprTyVarBndr :: TyVarBndr BndrVis -> Doc Source #
type Rep BndrVis |
Instance details Defined in Language.Haskell.TH.Syntax type Rep BndrVis = D1 ('MetaData "BndrVis" "Language.Haskell.TH.Syntax" "template-haskell" 'False) (C1 ('MetaCons "BndrReq" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BndrInvis" 'PrefixI 'False) (U1 :: Type -> Type))

class DefaultBndrFlag flag where Source #

Methods

defaultBndrFlag :: flag Source #

#### Instances

Instances details

DefaultBndrFlag BndrVis |
Instance details Defined in Language.Haskell.TH.Lib Methods defaultBndrFlag :: BndrVis Source #
DefaultBndrFlag Specificity |
Instance details Defined in Language.Haskell.TH.Lib Methods defaultBndrFlag :: Specificity Source #
DefaultBndrFlag () |
Instance details Defined in Language.Haskell.TH.Lib Methods 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`

plainTV :: DefaultBndrFlag flag => Name -> TyVarBndr flag Source #

kindedTV :: DefaultBndrFlag flag => Name -> Kind -> TyVarBndr flag Source #

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

Construct a `PlainTV` with a `BndrReq`.

plainTVInvis :: Name -> TyVarBndrVis Source #

Construct a `PlainTV` with a `BndrInvis`.

kindedTVReq :: Name -> Kind -> TyVarBndrVis Source #

Construct a `KindedTV` with a `BndrReq`.

kindedTVInvis :: Name -> Kind -> TyVarBndrVis Source #

Construct a `KindedTV` with a `BndrInvis`.

# Constructing `Specificity`

inferredSpec :: Specificity Source #

specifiedSpec :: Specificity Source #

# Constructing `BndrVis`

bndrReq :: BndrVis Source #

bndrInvis :: BndrVis Source #

# Modifying `TyVarBndr`s

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

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`.

elimTVFlag :: (Name -> flag -> r) -> (Name -> flag -> Kind -> r) -> TyVarBndr_ flag -> r Source #

Case analysis for a `TyVarBndr` that includes `flag`s in the continuation arguments. Note that `TyVarBndr`s did not include `flag`s prior to `template-haskell-2.17.0.0`, so on older versions of `template-haskell`, these `flag`s instead become `()`.

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 #

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

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

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

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

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

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 #

Traverse the `Name` of a `TyVarBndr`.

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 #

Traverse the `Kind` of a `TyVarBndr`.

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 of
      DataD _ _ 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 #

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

tvFlag :: TyVarBndr_ flag -> flag Source #

Extract the `flag` from a `TyVarBndr`. Note that `TyVarBndr`s did not include `flag`s prior to `template-haskell-2.17.0.0`, so on older versions of `template-haskell`, this functions instead returns `()`.