Type.Reflection (original) (raw)

Contents

Description

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

The interface provides [TypeRep](Type-Reflection.html#t:TypeRep "Type.Reflection"), a type representation which can be safely decomposed and composed. See Data.Dynamic for an example of this.

Since: 4.10.0.0

Synopsis

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 :~: b 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: 4.7.0.0

data a :~~: b 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: 4.10.0.0

Type representationsType-Indexed

data TypeRep a Source #

A concrete representation of a (monomorphic) type.[TypeRep](Type-Reflection.html#t:TypeRep "Type.Reflection") supports reasonably efficient equality.

pattern App :: forall k2 (t :: k2). () => forall k1 (a :: k1 -> k2) (b :: k1). 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 :: forall k (a :: k). () => IsApplication a ~ "" => TyCon -> TypeRep a Source #

Pattern match on a type constructor

pattern Con' :: forall k (a :: k). () => IsApplication 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

data Module #

Instances

Instances details