HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleBNFC-2.9.5Haskell2010

BNFC.PrettyPrint

Extends 'Text.PrettyPrint'.

  • 4 types
  • 1 class
  • 54 values
  • PackageBNFC-2.9.5
  • Exports59
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePrettyPrint.hs
valuetext :: String -> Doc
#

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.

newtypenewtype Doc
#

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.

Instances10Eq, Show, IsString, Generic, Semigroup, Monoid, …
datadata Mode
#

Rendering mode.

Constructors

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

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

value(<+>) :: Doc -> Doc -> Doc
#

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

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

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

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.

valuechar :: Char -> Doc
#

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

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

    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.

valueptext :: String -> Doc
#

Same as text. Used to be used for Bytestrings.

valuepunctuate :: Doc -> [Doc] -> [Doc]
#
punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]
valuezeroWidthText :: String -> Doc
#

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

classclass Pretty a where
#

Overloaded function pretty.

Methods

Instances8Pretty, …
valueparensIf :: Bool -> Doc -> Doc
#

Put parens around document if given condition is true.

Example1 expression
parensIf True "foo"(foo)
Example1 expression
parensIf False "bar"bar
value($++$) :: Doc -> Doc -> Doc
#

Separate vertically by a blank line.

Example1 expression
"foo" $++$ "bar"foobar
Example1 expression
"foo" $++$ emptyfoo
valuevsep :: [Doc] -> Doc
#

List version of $++$.

Example1 expression
vsep [ "foo", nest 4 "bar" ]foo    bar
Example1 expression
vsep []
valuevcat' :: [Doc] -> Doc
#

List version of PrettyPrint.$+$.

Example1 expression
vcat' [text "abc", nest 4 (text "def")]abc    def
value(<=>) :: Doc -> Doc -> Doc
#

Pretty print separator with = (for assignments...).

Example1 expression
"a" <=> "123"a = 123
valueprettyList
  1. :: Int

    Indentation.

  2. -> Doc

    Preamble.

  3. -> Doc

    Left parenthesis.

  4. -> Doc

    Right parenthesis.

  5. -> Doc

    Separator (usually not including spaces).

  6. -> [Doc]

    List item.

  7. -> Doc
#

Print a list of 0-1 elements on the same line as some preamble and from 2 elements on the following lines, indented.

Example3 expressions
prettyList 2 ("foo" <+> equals) lbrack rbrack comma []foo = []prettyList 2 ("foo" <+> equals) lbrack rbrack comma [ "a" ]foo = [a]prettyList 2 ("foo" <+> equals) lbrack rbrack comma [ "a", "b" ]foo =  [ a  , b  ]

Used in the Agda backend.

valuecodeblock :: Int -> [Doc] -> Doc
#

Code block. A block of C/Java code, surrounded by {} and indented.

Example1 expression
codeblock 4 ["abc", "def"]{    abc    def}

Used in the C backend.