HORIZON HASKELLDocslts/ghc-10.0.x04404a62026-10-19Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 04404a6 · 2026-10-19

Modulepretty-1.1.3.6Haskell98

Text.PrettyPrint.Annotated

This module provides a version of pretty that allows for annotations to be attached to documents. Annotations are arbitrary pieces of metadata that can be attached to sub-documents.

This module should be used as opposed to the Text.PrettyPrint.Annotated.HughesPJ module. Both are equivalent though as this module simply re-exports the other.

Contents
  1. The document type
  2. Constructing documents
  3. Converting values into documents
  4. Simple derived documents
  5. Wrapping documents in delimiters
  6. Combining documents
  7. Annotating documents
  8. Predicates on documents
  9. Rendering documents
  10. Default rendering
  11. Annotation rendering
  12. Rendering with a particular style
  13. General rendering
Synopsis
  • Packagepretty-1.1.3.6
  • Exports54
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceAnnotated.hs

The document type

datadata Doc a

The abstract type of documents. A Doc represents a set of layouts. A Doc with no occurrences of Union or NoDoc represents just one layout.

Instances9Functor, Eq, Show, IsString, Generic, Semigroup, …

Constructing documents

Converting values into documents

valuechar :: Char -> Doc a

A document of height and width 1, containing a literal character.

valuetext :: String -> Doc a

A document of height 1 containing a literal string. text satisfies the following laws:

The side condition on the last law is necessary because text "" has height 1, while empty has no height.

valueint
  1. :: Int
  2. -> Doc a
    int n = text (show n)
#

Simple derived documents

Wrapping documents in delimiters

Combining documents

value($$) :: Doc a -> Doc a -> Doc a

Above, except that if the last line of the first argument stops at least one position before the first line of the second begins, these two lines are overlapped. For example:

   text "hi" $$ nest 5 (text "there")

lays out as

   hi   there

rather than

   hi
        there

$$ is associative, with identity empty, and also satisfies

  • (x $$ y) <> z = x $$ (y <> z), if y non-empty.

Annotating documents

Predicates on documents

Rendering documents

Default rendering

Annotation rendering

datadata Span a

A Span represents the result of an annotation after a Doc has been rendered, capturing where the annotation now starts and ends in the rendered output.

Instances3Functor, Eq, Show
  • Functor SpanDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ
  • Eq a => Eq (Span a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ
  • Show a => Show (Span a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ

Rendering with a particular style

datadata Style

A rendering style. Allows us to specify constraints to choose among the many different rendering options.

Constructors

  • Style
    • mode :: Mode

      The rendering mode.

    • lineLength :: Int

      Maximum length of a line, in characters.

    • ribbonsPerLine :: Float

      Ratio of line length to ribbon length. A ribbon refers to the characters on a line excluding indentation. So a lineLength of 100, with a ribbonsPerLine of 2.0 would only allow up to 50 characters of ribbon to be displayed on a line, while allowing it to be indented up to 50 characters.

Instances4Eq, Show, Generic, Rep
valuestyle :: Style

The default style (mode=PageMode, lineLength=100, ribbonsPerLine=1.5).

General rendering

valuefullRender
  1. :: Mode

    Rendering mode.

  2. -> Int

    Line length.

  3. -> Float

    Ribbons per line.

  4. -> (TextDetails -> a -> a)

    What to do with text.

  5. -> a

    What to do at the end.

  6. -> Doc b

    The document.

  7. -> a

    Result.

The general rendering interface. Please refer to the Style and Mode types for a description of rendering mode, line length and ribbons.

valuefullRenderAnn
  1. :: Mode

    Rendering mode.

  2. -> Int

    Line length.

  3. -> Float

    Ribbons per line.

  4. -> (AnnotDetails b -> a -> a)

    What to do with text.

  5. -> a

    What to do at the end.

  6. -> Doc b

    The document.

  7. -> a

    Result.

The general rendering interface, supporting annotations. Please refer to the Style and Mode types for a description of rendering mode, line length and ribbons.

datadata Mode

Rendering mode.

Constructors

Instances4Eq, Show, Generic, Rep
datadata TextDetails

A TextDetails represents a fragment of text that will be output at some point in a Doc.

Constructors

  • Chr !Char

    A single Char fragment

  • Str String

    A whole String fragment

  • PStr String

    Used to represent a Fast String fragment but now deprecated and identical to the Str constructor.

Instances5Eq, Show, Generic, NFData, Rep