The class Typeable allows a concrete representation of a type to be calculated.
Modulebase-4.20.2.0Haskell2010
Data.Typeable
The Typeable class reifies types to some extent by associating type representations to types. These type representations can be compared, and one can in turn define a type-safe cast operation. To this end, an unsafe cast is guarded by a test for type (representation) equivalence. The module Data.Dynamic uses Typeable for an implementation of dynamics. The module Data.Data uses Typeable and type-safe cast (but not dynamics) to support the "Scrap your boilerplate" style of generic programming.
Compatibility Notes
Since GHC 8.2, GHC has supported type-indexed type representations.
Data.Typeable provides type representations which are qualified over this
index, providing an interface very similar to the Typeable notion seen in
previous releases. For the type-indexed interface, see Type.Reflection.
Since GHC 7.10, all types automatically have Typeable instances derived.
This is in contrast to previous releases where Typeable had to be
explicitly derived using the DeriveDataTypeable language extension.
Since GHC 7.8, Typeable is poly-kinded. The changes required for this might break some old programs involving Typeable. More details on this, including how to fix your code, can be found on the PolyTypeable wiki page
- 5 types
- 1 class
- 31 values
- Packagebase-4.20.2.0
- Exports37
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceTypeable.hs
The Typeable class
3 declarationsObserve a type representation for the type of a value.
Takes a value of type a and returns a concrete representation
of that type.
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-safe cast
6 declarationsThe type-safe cast operation
Extract a witness of equality of two types
Extract a witness of heterogeneous equality of two types
Decide an equality of two types
Decide heterogeneous equality of two types.
A flexible variation parameterised in a type constructor
Generalized casts for higher-order kinds
2 declarationsCast over k1 -> k2
Cast over k1 -> k2 -> k3
A canonical proxy type
1 declarationProxy is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).
Historically, Proxy :: Proxy a is a safer alternative to the
undefined :: a idiom.
Proxy :: Proxy (Void, Int -> Int)Proxy
Proxy can even hold types of higher kinds,
Proxy :: Proxy EitherProxy
Proxy :: Proxy FunctorProxy
Proxy :: Proxy complicatedStructureProxy
Instances27Generic1, Monad, Functor, Applicative, Foldable, Traversable, …
Generic1 ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsMonad ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyFunctor ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyApplicative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyFoldable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableAlternative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonadPlus ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonadZip ProxyDefined in base-4.20.2.0 · Control.Monad.ZipEq1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesOrd1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesRead1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesShow1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesContravariant ProxyDefined in base-4.20.2.0 · Data.Functor.ContravariantBounded (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyEnum (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyEq (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyData t => Data (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataOrd (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyRead (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyShow (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyIx (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyGeneric (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxytype Rep (Proxy t) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"Proxy"
"GHC.Internal.Data.Proxy"
"ghc-internal"
'False) (C1 ('MetaCons"Proxy"
'PrefixI 'False) U1)type Rep1 Proxy = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"Proxy"
"GHC.Internal.Data.Proxy"
"ghc-internal"
'False) (C1 ('MetaCons"Proxy"
'PrefixI 'False) U1)
Type representations
4 declarationsA quantified type representation.
Force a TypeRep to normal form.
Show a type representation
Build a function type.
Observing type representations
5 declarationsApplies a type to a function type. Returns: Just u if the first argument
represents a function of type t -> u and the second argument represents a
function of type t. Otherwise, returns Nothing.
Splits a type constructor application. Note that if the type constructor is polymorphic, this will not return the kinds that were used.
Observe the argument types of a type representation
Observe the type constructor of a quantified type representation.
Takes a value of type a and returns a concrete representation
of that type.