type-reflection-1.0: Support functions to work with type representations.
CopyrightRichard Eisenberg
LicenseMIT
Maintainerrae@richarde.dev
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageGHC2021

Type.Reflection.Name

Description

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), newtypes are provided for each format.

Synopsis

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.

Constructors

MkUnqualified Text 

Instances

Instances details
IsString Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Monoid Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Semigroup Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Show Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Eq Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Ord Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Hashable Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

TypeText Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Methods

renderTyCon :: TyCon -> Unqualified Source #

renderTypeRep :: forall {k} (t :: k). TypeRep t -> Unqualified Source #

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

newtype Qualified Source #

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.

Constructors

MkQualified Text 

Instances

Instances details
IsString Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Monoid Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Semigroup Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Show Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Eq Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Ord Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Hashable Qualified Source # 
Instance details

Defined in Type.Reflection.Name

TypeText Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Methods

renderTyCon :: TyCon -> Qualified Source #

renderTypeRep :: forall {k} (t :: k). TypeRep t -> Qualified Source #

getQualified :: Qualified -> Text Source #

Extract the contents of a Qualified rendering

showQualified :: TypeRep t -> Qualified Source #

Convert a TypeRep into a Qualified representation

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.

Constructors

MkPackageQualified Text 

Instances

Instances details
IsString PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

Monoid PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

Semigroup PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

Show PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

Eq PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

Ord PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

Hashable PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

TypeText PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

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.

Minimal complete definition

renderTyCon

Instances

Instances details
TypeText PackageQualified Source # 
Instance details

Defined in Type.Reflection.Name

TypeText Qualified Source # 
Instance details

Defined in Type.Reflection.Name

Methods

renderTyCon :: TyCon -> Qualified Source #

renderTypeRep :: forall {k} (t :: k). TypeRep t -> Qualified Source #

TypeText Unqualified Source # 
Instance details

Defined in Type.Reflection.Name

Methods

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, not String, and we get TYPE ('BoxedRep 'Lifted), not Type.