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

ModuleAgda-2.7.0.1Haskell2010

Agda.Syntax.Common.Pretty

Pretty printing functions.

  • 4 types
  • 1 class
  • 73 values
  • PackageAgda-2.7.0.1
  • Exports81
  • LanguageHaskell2010
  • LicenceMIT
  • SourcePretty.hs
classclass Pretty a where
#

While Show is for rendering data in Haskell syntax, Pretty is for displaying data to the world, i.e., the user and the environment.

Atomic data has no inner document structure, so just implement pretty as pretty a = text $ ... a ....

Methods

Instances282Pretty, …
typetype Doc = Doc Aspects
#

The type of documents. We use documents annotated by Aspects to record syntactic highlighting information that is generated during pretty-printing.

valuealign :: Int -> [(String, Doc)] -> Doc
#

align max rows lays out the elements of rows in two columns, with the second components aligned. The alignment column of the second components is at most max characters to the right of the left-most column.

Precondition: max > 0.

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.

valuechar :: Char -> Doc a
#

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

datadata Mode
#

Rendering mode.

Constructors

Instances4Eq, Show, Generic, Rep
value(<+>) :: Doc a -> Doc a -> Doc a
#

Beside, separated by space, unless one of the arguments is empty. <+> is associative, with identity empty.

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.

valueannotate :: a -> Doc a -> Doc a
#

Attach an annotation to a document.

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

Above, with no overlapping. $+$ is associative, with identity empty.

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
valueint
  1. :: Int
  2. -> Doc a
    int n = text (show n)
#
constructorChr !Char
#

A single Char fragment

constructorPStr String
#

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

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
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.

valueptext :: String -> Doc a
#

Same as text. Used to be used for Bytestrings.

valuestyle :: Style
#

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

valuezeroWidthText :: String -> Doc a
#

Some text, but without any width. Use for non-printing text such as a HTML or Latex tags

method(<>) :: a -> a -> a
#

An associative operation.

Examples
Example1 expression
[1,2,3] <> [4,5,6][1,2,3,4,5,6]
Example1 expression
Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
Example1 expression
putStr "Hello, " <> putStrLn "World!"Hello, World!