HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleprettyprinter-1.7.1Haskell2010

Prettyprinter.Internal.Type

Internal module with stability guarantees

This module exposes the internals of the Doc type so other libraries can write adaptors to/from it. For all other uses, please use only the API provided by non-internal modules.

Although this module is internal, it follows the usual package versioning policy, AKA Haskell’s version of semantic versioning. In other words, this module is as stable as the public API.

  • 1 type
datadata Doc ann
#

The abstract data type Doc ann represents pretty documents that have been annotated with data of type ann.

More specifically, a value of type Doc represents a non-empty set of possible layouts of a document. The layout functions select one of these possibilities, taking into account things like the width of the output document.

The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as

  • color information (e.g. when rendering to the terminal)

  • mouseover text (e.g. when rendering to rich HTML)

  • whether to show something or not (to allow simple or detailed versions)

The simplest way to display a Doc is via the Show class.

Example1 expression
putStrLn (show (vsep ["hello", "world"]))helloworld

Constructors

  • Fail

    Occurs when flattening a line. The layouter will reject this document, choosing a more suitable rendering.

  • Empty

    The empty document; conceptually the unit of Cat

  • Char !Char

    invariant: not 'n'

  • Text !Int !Text

    Invariants: at least two characters long, does not contain 'n'. For empty documents, there is Empty; for singleton documents, there is Char; newlines should be replaced by e.g. Line.

    Since the frequently used length of Text is O(length), we cache it in this constructor.

  • Line

    Hard line break

  • FlatAlt (Doc ann) (Doc ann)

    Lay out the first Doc, but when flattened (via group), prefer the second.

    The layout algorithms work under the assumption that the first alternative is less wide than the flattened second alternative.

  • Cat (Doc ann) (Doc ann)

    Concatenation of two documents

  • Nest !Int (Doc ann)

    Document indented by a number of columns

  • Union (Doc ann) (Doc ann)

    Invariant: The first lines of first document should be longer than the first lines of the second one, so the layout algorithm can pick the one that fits best. Used to implement layout alternatives for group.

  • Column (Int -> Doc ann)

    React on the current cursor position, see column

  • WithPageWidth (PageWidth -> Doc ann)

    React on the document's width, see pageWidth

  • Nesting (Int -> Doc ann)

    React on the current nesting level, see nesting

  • Annotated ann (Doc ann)

    Add an annotation to the enclosed Doc. Can be used for example to add styling directives or alt texts that can then be used by the renderer.

Instances7Functor, Show, IsString, Generic, Semigroup, Monoid, …