Type.Reflection (original) (raw)
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#
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: base-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: base-4.10.0.0
Type representationsType-Indexed
A concrete representation of a (monomorphic) type.[TypeRep](Type-Reflection.html#t:TypeRep "Type.Reflection") supports reasonably efficient equality.
pattern TypeRep :: forall {k :: Type} (a :: k). () => Typeable @k a => TypeRep @k 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 :: 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). () => NotApplication a => TyCon -> TypeRep a Source #
Pattern match on a type constructor
pattern Con' :: forall k (a :: k). () => 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