Type.Reflection (original) (raw)

The Typeable class

class Typeable (a :: k) Source #

The class [Typeable](Type-Reflection.html#t:Typeable "Type.Reflection") allows a concrete representation of a type to be calculated.

Minimal complete definition

typeRep#

Propositional equality

data (a :: k) :~: (b :: k) where infix 4 Source #

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.

Since: base-4.7.0.0

Constructors

| Refl :: forall {k} (a :: k). a :~: a | | | ----------------------------------------------------------------------------------------- | |

data (a :: k1) :~~: (b :: k2) where infix 4 Source #

Kind heterogeneous propositional equality. Like [:~:](Type-Reflection.html#t::-126-: "Type.Reflection"), a :~~: b is inhabited by a terminating value if and only if a is the same type as b.

Since: base-4.10.0.0

Type representationsType-Indexed

data TypeRep (a :: k) Source #

TypeRep is a concrete representation of a (monomorphic) type.[TypeRep](Type-Reflection.html#v:TypeRep "Type.Reflection") supports reasonably efficient equality. See Note [Grand plan for Typeable] in GHC.Tc.Instance.Typeable

pattern TypeRep :: () => Typeable a => TypeRep a Source #

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 -}

Since: base-4.17.0.0

pattern App :: forall k2 t k1 a b. () => t ~ a b => TypeRep a -> TypeRep b -> TypeRep t Source #

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

pattern Con' :: () => NotApplication a => TyCon -> [SomeTypeRep] -> TypeRep a Source #

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

QuantifiedType constructorsModule names