Haskell types are represented as terms using the TypeRep
abstract type:
data TypeRep -- abstract, instance of: Eq, Show
data TyCon -- abstract, instance of: Eq, Show
mkTyCon :: String -> TyCon
mkAppTy :: TyCon -> [TypeRep] -> TypeRep
mkFunTy :: TypeRep -> TypeRep -> TypeRep
applyTy :: TypeRep -> TypeRep -> Maybe TypeRep
mkAppTy applies a type constructor to a sequence of types,
returning a type.mkFunTy is a special case of mkAppTy, applying
the function type constructor to a pair of types.applyTy applies a type to a function type. If possible,
the result type is returned.TyCon. TypeReps can be compared for equality.
Type equality is used when converting a Dynamic value into a
value of some specific type, comparing the type representation that
the Dynamic value embeds with equality of the type representation
of the type we're trying to convert the dynamically-typed value into.TypeReps to be implemented
efficiently, the abstract TyCon type is used, with
the constructor function mkTyCon provided:
mkTyCon :: String -> TyCon
An implementation of the Dynamic interface guarantees the
following,
mkTyCon "a" == mkTyCon "a"
A really efficient implementation is possible if we guarantee/demand
that the strings are unique, and for a particular type constructor,
the application mkTyCon to the string that represents the type
constructor is never duplicated. Q: Would this constraint be
unworkable in practice?TyCon and TypeRep are instances of the Show type
classes. To have tuple types be shown in infix form, the Show
instance guarantees that type constructors consisting of n-commas,
i.e., (mkTyCon ",,,,"), is shown as an (n+1) tuple in infix
form.