HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleghc-internal-10.0.0Haskell2010

GHC.Internal.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

Contents
  1. The Typeable class
  2. Propositional equality
  3. Type-safe cast
  4. Generalized casts for higher-order kinds
  5. A canonical proxy type
  6. Type representations
  7. Observing type representations
  8. Type constructors
  9. For backwards compatibility
Synopsis

The Typeable class

classclass Typeable (a :: k) where

The class Typeable allows a concrete representation of a type to be calculated.

Propositional equality

datadata (:~:) (a :: k) (b :: k) where

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.

Constructors

Instances10Category, TestCoercion, TestEquality, Bounded, Enum, Eq, …
  • Category (:~:)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Category
  • TestCoercion ((:~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Coercion
  • TestEquality ((:~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Bounded (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Enum (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Eq (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • (a ~ b, Data a) => Data (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Data
  • Ord (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~ b => Read (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Show (a :~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
datadata (:~~:) (a :: k1) (b :: k2) where

Kind heterogeneous propositional equality. Like :~:, a :~~: b is inhabited by a terminating value if and only if a is the same type as b.

Constructors

Instances10Category, TestCoercion, TestEquality, Bounded, Enum, Eq, …
  • Category (:~~:)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Category
  • TestCoercion ((:~~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Coercion
  • TestEquality ((:~~:) a)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Bounded (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Enum (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Eq (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • (Typeable i, Typeable j, Typeable a, Typeable b, a ~~ b) => Data (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Data
  • Ord (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • a ~~ b => Read (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality
  • Show (a :~~: b)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Type.Equality

Type-safe cast

Generalized casts for higher-order kinds

A canonical proxy type

datadata Proxy (t :: k)

Proxy 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.

Example1 expression
Proxy :: Proxy (Void, Int -> Int)Proxy

Proxy can even hold types of higher kinds,

Example1 expression
Proxy :: Proxy EitherProxy
Example1 expression
Proxy :: Proxy FunctorProxy
Example1 expression
Proxy :: Proxy complicatedStructureProxy
Instances22Generic1, Monad, Functor, Applicative, Foldable, Traversable, …
  • Generic1 ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Monad ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Functor ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Applicative ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Foldable ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Foldable
  • Traversable ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Traversable
  • Alternative ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • MonadPlus ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • MonadZip ProxyDefined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.Zip
  • Bounded (Proxy t)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Enum (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Eq (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Data t => Data (Proxy t)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Data
  • Ord (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Read (Proxy t)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Show (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Ix (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Generic (Proxy t)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • Semigroup (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • Monoid (Proxy s)Defined in ghc-internal-10.0.0 · GHC.Internal.Data.Proxy
  • type Rep (Proxy t) = D1 ('MetaData "Proxy" "GHC.Internal.Data.Proxy" "ghc-internal" 'False) (C1 ('MetaCons "Proxy" 'PrefixI 'False) U1)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics
  • type Rep1 Proxy = D1 ('MetaData "Proxy" "GHC.Internal.Data.Proxy" "ghc-internal" 'False) (C1 ('MetaCons "Proxy" 'PrefixI 'False) U1)Defined in ghc-internal-10.0.0 · GHC.Internal.Generics

Type representations

Observing type representations

Applies 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.

Type constructors

datadata TyCon
#
Instances3Eq, Ord, Show
  • Eq TyConDefined in ghc-internal-10.0.0 · GHC.Internal.Classes
  • Ord TyConDefined in ghc-internal-10.0.0 · GHC.Internal.Classes
  • Show TyConDefined in ghc-internal-10.0.0 · GHC.Internal.Show

For backwards compatibility