The class Typeable allows a concrete representation of a type to be calculated.
Modulebase-compat-0.14.1Haskell2010
Type.Reflection.Compat
- 6 types
- 1 class
- 21 values
- Packagebase-compat-0.14.1
- Exports34
- LanguageHaskell2010
- LicenceMIT
- SourceInternal.hs
Use 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 -}
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
Instances5TestEquality, Eq, Ord, Show, NFData
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.InternalNFData (TypeRep a)Defined in deepseq-1.5.0.0 · Control.DeepSeq
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 -}
Type equality decision
Instances4Eq, Ord, Show, NFData
Eq TyConDefined in ghc-prim-0.12.0 · GHC.ClassesOrd TyConDefined in ghc-prim-0.12.0 · GHC.ClassesShow TyConDefined in ghc-internal-9.1003.0 · GHC.Internal.ShowNFData TyConDefined in deepseq-1.5.0.0 · Control.DeepSeqNOTE: Prior to
deepseq-1.4.4.0this instance was only defined forbase-4.8.0.0and later.
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
Kind heterogeneous propositional equality. Like :~:, a :~~: b is
inhabited by a terminating value if and only if a is the same type as b.
Instances13Category, TestCoercion, TestEquality, NFData2, NFData1, Bounded, …
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.EqualityNFData2 (:~~:)Defined in deepseq-1.5.0.0 · Control.DeepSeqNFData1 ((:~~:) a)Defined in deepseq-1.5.0.0 · Control.DeepSeqa ~~ 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.EqualityNFData (a :~~: b)Defined in deepseq-1.5.0.0 · Control.DeepSeq
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.
Instances13Category, TestCoercion, TestEquality, NFData2, NFData1, Bounded, …
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.EqualityNFData2 (:~:)Defined in deepseq-1.5.0.0 · Control.DeepSeqNFData1 ((:~:) a)Defined in deepseq-1.5.0.0 · Control.DeepSeqa ~ 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.EqualityNFData (a :~: b)Defined in deepseq-1.5.0.0 · Control.DeepSeq
Helper to fully evaluate TypeRep for use as NFData(rnf) implementation
Observe the type constructor of a type representation
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)
Type equality
Helper to fully evaluate SomeTypeRep for use as NFData(rnf)
implementation
Takes a value of type a and returns a concrete representation
of that type.
Observe the type constructor of a quantified type representation.
Observe the kind of a type.
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
Helper to fully evaluate TyCon for use as NFData(rnf) implementation
Use 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 -}
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 -}
Type equality decision