Data.Typeable (original) (raw)
Description
The [Typeable](Data-Typeable.html#t: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.
The Typeable class
class Typeable a whereSource
The class [Typeable](Data-Typeable.html#t:Typeable)
allows a concrete representation of a type to be calculated.
Methods
Takes a value of type a
and returns a concrete representation of that type. The value of the argument should be ignored by any instance of [Typeable](Data-Typeable.html#t:Typeable)
, so that it is safe to pass [undefined](Prelude.html#v:undefined)
as the argument.
Type-safe cast
Type representations
data TypeRep Source
A concrete representation of a (monomorphic) type. [TypeRep](Data-Typeable.html#t:TypeRep)
supports reasonably efficient equality.
tyConString :: TyCon -> StringSource
Deprecated: renamed to tyConName; tyConModule and tyConPackage are also available.
Observe string encoding of a type representation
Construction of type representations
mkTyConSource
Deprecated: either derive Typeable, or use mkTyCon3 instead
Backwards-compatible API
mkTyCon3Source
Builds a [TyCon](Data-Typeable.html#t:TyCon)
object representing a type constructor. An implementation of Data.Typeable should ensure that the following holds:
A==A' ^ B==B' ^ C==C' ==> mkTyCon A B C == mkTyCon A' B' C'
Observation of type representations
The other Typeable classes
Note: The general instances are provided for GHC only.
Default instances
Note: These are not needed by GHC, for which these instances are generated by general instance declarations.