The Types module aims at providing a representation for (first-order) monomorphic Haskell types. Two type representations are equal if and only if the represented types have identical definitions. Thus a type representation consists of a type term and the smallest list of all (data or newtype) definitions needed either in the type term or in another definition. The list of definitions is sorted to make representations unique.
The main use of type representations is to provide a type index for
storing Haskell values externally and for reading them back into a
running program without sacrificing type safety. Just reading them
back with the Read
class is not sufficient because
-
Read
does not distinguish betweenInt
andInteger
,Float
andDouble
y -
Read
cannot avoid accidental matches of constructor names
Meanwhile, the Data.Typeable
class of GHC provides an encoding with similar
goals.
Documentation
A type specification consists of a type representation TyRep
and a list of
type declarations.
A type representation is built from base types, type variables, tuples, and references to data-defined types.
A data declaration consists of the name of the data type, a list of type variables, and a list of constructor representations.
A constructor is represented by its name, a list of field names (if defined using record notation), and the list of its argument types
Types Bool | |
Types Char | |
Types Double | |
Types Float | |
Types Int | |
Types Integer | |
Types () | |
Types a => Types [a] | |
Types a => Types (Maybe a) | |
(Types a, Types b) => Types (Either a b) | |
(Types a, Types b) => Types (a, b) | |
(Types a, Types b, Types c) => Types (a, b, c) | |
(Types a, Types b, Types c, Types d) => Types (a, b, c, d) | |
(Types a, Types b, Types c, Types d, Types e) => Types (a, b, c, d, e) |