HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecardano-api-11.7.0.0

Cardano.Api.Pretty

  • 4 types
  • 1 class
  • 19 values
value(<+>) :: Doc ann -> Doc ann -> Doc ann
#

(x <+> y) concatenates document x and y with a space in between.

Example1 expression
"hello" <+> "world"hello world
x <+> y = x <> space <> y
valuehsep :: [Doc ann] -> Doc ann
#

(hsep xs) concatenates all documents xs horizontally with <+>, i.e. it puts a space between all entries.

Example1 expression
let docs = Util.words "lorem ipsum dolor sit amet"
Example1 expression
hsep docslorem ipsum dolor sit amet

hsep does not introduce line breaks on its own, even when the page is too narrow:

Example1 expression
putDocW 5 (hsep docs)lorem ipsum dolor sit amet

For automatic line breaks, consider using fillSep instead.

valuevsep :: [Doc ann] -> Doc ann
#

(vsep xs) concatenates all documents xs above each other. If a group undoes the line breaks inserted by vsep, the documents are separated with a space instead.

Using vsep alone yields

Example1 expression
"prefix" <+> vsep ["text", "to", "lay", "out"]prefix texttolayout

grouping a vsep separates the documents with a space if it fits the page (and does nothing otherwise). See the sep convenience function for this use case.

The align function can be used to align the documents under their first element:

Example1 expression
"prefix" <+> align (vsep ["text", "to", "lay", "out"])prefix text       to       lay       out

Since grouping a vsep is rather common, sep is a built-in for doing that.

newtypenewtype ShowOf a
#

Constructors

Instances4Show, Pretty, ToJSON, ToJSONKey
  • Show a => Show (ShowOf a)Defined in cardano-api-11.7.0.0 · Cardano.Api.Pretty.Internal.ShowOf
  • Show a => Pretty (ShowOf a)Defined in cardano-api-11.7.0.0 · Cardano.Api.Pretty.Internal.ShowOf
  • Show a => ToJSON (ShowOf a)Defined in cardano-api-11.7.0.0 · Cardano.Api.Pretty.Internal.ShowOf
  • Show a => ToJSONKey (ShowOf a)Defined in cardano-api-11.7.0.0 · Cardano.Api.Pretty.Internal.ShowOf
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
Instances9Functor, PrettyAnn, Show, IsString, Generic, Semigroup, …
classclass Pretty a where
#

Overloaded conversion to Doc.

Laws:

  1. output should be pretty. :-)

Methods

  • pretty :: a -> Doc ann
    Example1 expression
    pretty 1 <+> pretty "hello" <+> pretty 1.2341 hello 1.234
  • prettyList :: [a] -> Doc ann

    prettyList is only used to define the instance Pretty a => Pretty [a]. In normal circumstances only the pretty function is used.

    Example1 expression
    prettyList [1, 23, 456][1, 23, 456]
Instances373Pretty, …
datadata Text
#

A space efficient, packed, unboxed Unicode text type.

Instances127IsList, Eq, Data, Ord, Read, Show, …

Orphan instances

1 instance