The class Typeable allows a concrete representation of a type to be calculated.
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
- Packageghc-internal-9.1003.0
- Exports31
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceReflection.hs
The Typeable class
3 declarationsUse a TypeRep as Typeable evidence.
The TypeRep pattern synonym brings a Typeable constraint into scope and can be used in place of withTypeable.
f :: TypeRep a -> ..
f rep = withTypeable {- Typeable a in scope -}
f :: TypeRep a -> ..
f TypeRep = {- Typeable a in scope -}
Propositional equality
2 declarationsPropositional 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.
Instances10Category, TestCoercion, TestEquality, Bounded, Enum, Eq, …
Category (:~:)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.CategoryTestCoercion ((:~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.CoercionTestEquality ((:~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equalitya ~ b => Bounded (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equalitya ~ b => Enum (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.EqualityEq (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.DataOrd (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equalitya ~ b => Read (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.EqualityShow (a :~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
Kind heterogeneous propositional equality. Like :~:, a :~~: b is
inhabited by a terminating value if and only if a is the same type as b.
Instances10Category, TestCoercion, TestEquality, Bounded, Enum, Eq, …
Category (:~~:)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.CategoryTestCoercion ((:~~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.CoercionTestEquality ((:~~:) a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equalitya ~~ b => Bounded (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equalitya ~~ b => Enum (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.EqualityEq (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.DataOrd (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equalitya ~~ b => Read (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.EqualityShow (a :~~: b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Equality
Type representations
0 declarationsType-Indexed
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.InternalEq (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.InternalOrd (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.InternalShow (TypeRep a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
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 -}
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 match on a type constructor
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
pattern Fun :: () => (k ~ Type, fun ~~ (arg -> res)) => TypeRep arg -> TypeRep res -> TypeRep funThe function type constructor.
For instance,
typeRep @(Int -> Char) === Fun (typeRep @Int) (typeRep @Char)
Observe the type constructor of a type representation
Helper to fully evaluate TypeRep for use as NFData(rnf) implementation
Type equality
Type equality decision
Observe the kind of a type.
Quantified
A non-indexed type representation.
Constructors
SomeTypeRep :: !TypeRep a -> SomeTypeRep
Instances3Eq, Ord, Show
Eq SomeTypeRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.InternalOrd SomeTypeRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.InternalShow SomeTypeRepDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Typeable.Internal
Takes a value of type a and returns a concrete representation
of that type.
Observe the type constructor of a quantified type representation.
Helper to fully evaluate SomeTypeRep for use as NFData(rnf)
implementation
Type constructors
5 declarationsModule names
4 declarationsHelper to fully evaluate TyCon for use as NFData(rnf) implementation