HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleghc-internal-10.0.0Haskell2010

GHC.Internal.Type.Reflection

This provides a type-indexed type representation mechanism, similar to that described by,

  • Simon Peyton-Jones, Stephanie Weirich, Richard Eisenberg, Dimitrios Vytiniotis. "A reflection on types". Proc. Philip Wadler's 60th birthday Festschrift, Edinburgh (April 2016).

The interface provides TypeRep, a type representation which can be safely decomposed and composed. See Data.Dynamic for an example of this.

Contents
  1. The Typeable class
  2. Propositional equality
  3. Type representations
  4. Type-Indexed
  5. Quantified
  6. Type constructors
  7. Module names
Synopsis

The Typeable class

classclass Typeable (a :: k) where

The class Typeable allows a concrete representation of a type to be calculated.

Propositional equality

datadata (:~:) (a :: k) (b :: k) where

Propositional equality. If a :~: b is inhabited by some terminating value, then the type a is the same as the type b. To use this equality in practice, pattern-match on the a :~: b to get out the Refl constructor; in the body of the pattern-match, the compiler knows that a ~ b.

Constructors

Instances10Category, TestCoercion, TestEquality, Bounded, Enum, Eq, …
  • Category (:~:)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Category
  • TestCoercion ((:~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Coercion
  • TestEquality ((:~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Bounded (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Enum (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Eq (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • (a ~ b, Data a) => Data (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Data
  • Ord (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Read (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Show (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
datadata (:~~:) (a :: k1) (b :: k2) where

Kind heterogeneous propositional equality. Like :~:, a :~~: b is inhabited by a terminating value if and only if a is the same type as b.

Constructors

Instances10Category, TestCoercion, TestEquality, Bounded, Enum, Eq, …
  • Category (:~~:)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Category
  • TestCoercion ((:~~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Coercion
  • TestEquality ((:~~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Bounded (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Enum (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Eq (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • (Typeable i, Typeable j, Typeable a, Typeable b, a ~~ b) => Data (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Data
  • Ord (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Read (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Show (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality

Type representations

Type-Indexed

datadata TypeRep (a :: k) where

TypeRep is a concrete representation of a (monomorphic) type. TypeRep supports reasonably efficient equality. See Note [Grand plan for Typeable] in GHC.Tc.Instance.Typeable

Instances4TestEquality, Eq, Ord, Show
  • TestEquality TypeRepDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Typeable.Internal
  • Eq (TypeRep a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Typeable.Internal
  • Ord (TypeRep a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Typeable.Internal
  • Show (TypeRep a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Typeable.Internal
patternpattern TypeRep :: () => Typeable a => TypeRep a

A explicitly bidirectional pattern synonym to construct a concrete representation of a type.

As an expression: Constructs a singleton TypeRep a given a implicit 'Typeable a' constraint:

TypeRep @a :: Typeable a => TypeRep a

As a pattern: Matches on an explicit TypeRep a witness bringing an implicit Typeable a constraint into scope.

f :: TypeRep a -> ..
f TypeRep = {- Typeable a in scope -}
patternpattern App :: () => t ~ a b => TypeRep a -> TypeRep b -> TypeRep t

A type application.

For instance,

typeRep @(Maybe Int) === App (typeRep @Maybe) (typeRep @Int)

Note that this will also match a function type,

typeRep @(Int# -> Char)
  ===
App (App arrow (typeRep @Int#)) (typeRep @Char)

where arrow :: TypeRep ((->) :: TYPE IntRep -> Type -> Type).

patternpattern Con :: () => NotApplication a => TyCon -> TypeRep a

Pattern match on a type constructor

patternpattern Con' :: () => NotApplication a => TyCon -> [SomeTypeRep] -> TypeRep a

Pattern match on a type constructor including its instantiated kind variables.

For instance,

App (Con' proxyTyCon ks) intRep = typeRep @(Proxy @Int)

will bring into scope,

proxyTyCon :: TyCon
ks         == [someTypeRep Type] :: [SomeTypeRep]
intRep     == typeRep Int
patternpattern Fun :: () => (k ~ Type, fun ~~ (arg -> res)) => TypeRep arg -> TypeRep res -> TypeRep fun

The function type constructor.

For instance,

typeRep @(Int -> Char) === Fun (typeRep @Int) (typeRep @Char)

Quantified

Type constructors

datadata TyCon
#
Instances3Eq, Ord, Show
  • Eq TyConDefined in ghc-internal-10.0.0 · GHC.Internal.Classes
  • Ord TyConDefined in ghc-internal-10.0.0 · GHC.Internal.Classes
  • Show TyConDefined in ghc-internal-10.0.0 · GHC.Internal.Show

Module names

datadata Module
#
Instances2Eq, Show
  • Eq ModuleDefined in ghc-internal-10.0.0 · GHC.Internal.Classes
  • Show ModuleDefined in ghc-internal-10.0.0 · GHC.Internal.Show