Copyright | Richard Eisenberg |
---|---|
License | MIT |
Maintainer | rae@richarde.dev |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
This module provides three different ways of serializing a TypeRep
into a Text
:
qualifying no names, qualifying all names, or package-qualifying all names. In order
to support meaningful notions of equality on these string representations (for e.g.
using them as keys in a map), newtype
s are provided for each format.
Synopsis
- newtype Unqualified = MkUnqualified Text
- getUnqualified :: Unqualified -> Text
- showUnqualified :: TypeRep t -> Unqualified
- newtype Qualified = MkQualified Text
- getQualified :: Qualified -> Text
- showQualified :: TypeRep t -> Qualified
- newtype PackageQualified = MkPackageQualified Text
- getPackageQualified :: PackageQualified -> Text
- showPackageQualified :: TypeRep t -> PackageQualified
- class (IsString tt, Monoid tt, Ord tt) => TypeText tt where
- renderTyCon :: TyCon -> tt
- renderTypeRep :: TypeRep t -> tt
- defaultRenderTypeRep :: forall tn outer_t. TypeText tn => TypeRep outer_t -> tn
Unqualified names
newtype Unqualified Source #
A rendering of a type where no components have module or package qualifications.
Data constructors used in types are preceded with a '
, and infix operator types
are printed without parentheses. Uses defaultRenderTypeRep
to render types; see
that function for further details.
Instances
getUnqualified :: Unqualified -> Text Source #
Extract the contents of an Unqualified
rendering
showUnqualified :: TypeRep t -> Unqualified Source #
Convert a TypeRep
into an Unqualified
representation
Qualified names
A rendering of a type where all components have module qualifications.
Data constructors used in types are preceded first with their module qualification,
and then with a '
, and infix operator types
are printed without parentheses. So we have Data.Proxy.'Proxy
for the Proxy
constructor.
Uses defaultRenderTypeRep
to render types; see
that function for further details.j
Note that module qualifications arise from the module that defines a type, even if this
is a hidden or internal module. This fact means that internal-structure changes in
your libraries may affect how your types are rendered, including changes in e.g. base
.
Instances
IsString Qualified Source # | |
Defined in Type.Reflection.Name fromString :: String -> Qualified # | |
Monoid Qualified Source # | |
Semigroup Qualified Source # | |
Show Qualified Source # | |
Eq Qualified Source # | |
Ord Qualified Source # | |
Defined in Type.Reflection.Name | |
Hashable Qualified Source # | |
Defined in Type.Reflection.Name | |
TypeText Qualified Source # | |
Defined in Type.Reflection.Name renderTyCon :: TyCon -> Qualified Source # renderTypeRep :: forall {k} (t :: k). TypeRep t -> Qualified Source # |
Package-qualified names
newtype PackageQualified Source #
A rendering of a type where all components have package and module qualifications
Data constructors used in types are preceded first with their package qualification,
and then their module qualification,
and then with a '
, and infix operator types
are printed without parentheses. So we have base.Data.Proxy.'Proxy
for the Proxy
constructor.
Uses defaultRenderTypeRep
to render types; see
that function for further details.
Note that module qualifications arise from the module that defines a type, even if this
is a hidden or internal module. This fact means that internal-structure changes in
your libraries may affect how your types are rendered, including changes in e.g. base
.
Instances
getPackageQualified :: PackageQualified -> Text Source #
Extract the contents of a PackageQualified
name
showPackageQualified :: TypeRep t -> PackageQualified Source #
Convert a TypeRep
into a PackageQualified
representation
Class-based access
class (IsString tt, Monoid tt, Ord tt) => TypeText tt where Source #
The TypeText
class describes how a TyCon
is rendered
into a textual representation, and it is used to render a TypeRep
by renderTypeRep
. The IsString
superclass is needed to insert
connectives like spaces, dots, and parentheses, and the Monoid
superclass is needed to stitch these pieces together.
Only renderTyCon
is needed for instances; if renderTypeRep
is
omitted, then the default rendering, via defaultRenderTypeRep
is
used. See that function for more details.
The only consistency law for TypeText
is this, holding for all
tr
of type TypeRep
:
case tr of Con' tc [] -> renderTypeRep tr == renderTyCon tc _ -> True
In other words, rendering a TypeRep
consisting only of a TyCon
is the same as rendering the TyCon
itself. If the TypeRep
is not
a plain TyCon
(with no kind arguments), then there are no applicable
laws. Note that the law uses ==
, even though Eq
is not a superclass
of TypeText
.
renderTyCon :: TyCon -> tt Source #
renderTypeRep :: TypeRep t -> tt Source #
Instances
TypeText PackageQualified Source # | |
Defined in Type.Reflection.Name renderTyCon :: TyCon -> PackageQualified Source # renderTypeRep :: forall {k} (t :: k). TypeRep t -> PackageQualified Source # | |
TypeText Qualified Source # | |
Defined in Type.Reflection.Name renderTyCon :: TyCon -> Qualified Source # renderTypeRep :: forall {k} (t :: k). TypeRep t -> Qualified Source # | |
TypeText Unqualified Source # | |
Defined in Type.Reflection.Name renderTyCon :: TyCon -> Unqualified Source # renderTypeRep :: forall {k} (t :: k). TypeRep t -> Unqualified Source # |
defaultRenderTypeRep :: forall tn outer_t. TypeText tn => TypeRep outer_t -> tn Source #
Render a TypeRep
into an instance of TypeText
. This follows the following
rules for how to render a type:
- Function types are rendered infix. If a function takes another function as an
argument, the argument function is rendered in parentheses (as required by the
right-associative
->
operator). - All other type constructors are rendered prefix, including the list constructor
[]
and the tuple constructors e.g.(,,)
, along with any other type operators. - All kind arguments to type constructors are rendered, with @ prefixes. Any non-atomic (that is, not simply a type constructor with no kind arguments) kinds are enclosed in parentheses.
- Non-atomic arguments are enclosed in parentheses.
- Type synonyms are always expanded. This means that we get
[] Char
, notString
, and we getTYPE ('BoxedRep 'Lifted)
, notType
.