HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-internal-9.1003.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.

  • 6 types
  • 1 class
  • 19 values

The Typeable class

3 declarations
classclass Typeable (a :: k) where
#

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

Propositional equality

2 declarations
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-9.1003.0 · GHC.Internal.Control.Category
  • TestCoercion ((:~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Coercion
  • TestEquality ((:~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Bounded (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Enum (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Eq (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • (a ~ b, Data a) => Data (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Read (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Show (a :~: b)Defined in ghc-internal-9.1003.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-9.1003.0 · GHC.Internal.Control.Category
  • TestCoercion ((:~~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Coercion
  • TestEquality ((:~~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Bounded (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Enum (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Eq (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • (Typeable i, Typeable j, Typeable a, Typeable b, a ~~ b) => Data (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Read (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
  • Show (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality

Type representations

0 declarations

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-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Eq (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Ord (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
  • Show (TypeRep a)Defined in ghc-internal-9.1003.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

5 declarations
datadata TyCon
#
Instances3Eq, Ord, Show
  • Eq TyConDefined in ghc-prim-0.12.0 · GHC.Classes
  • Ord TyConDefined in ghc-prim-0.12.0 · GHC.Classes
  • Show TyConDefined in ghc-internal-9.1003.0 · GHC.Internal.Show

Module names

4 declarations
datadata Module
#
Instances2Eq, Show
  • Eq ModuleDefined in ghc-prim-0.12.0 · GHC.Classes
  • Show ModuleDefined in ghc-internal-9.1003.0 · GHC.Internal.Show