h$ͧ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                                                                              Safe-Inferred prettyprinter Raise a hard  if there is a  in a . prettyprinter Raise a hard  when an annotation terminator is encountered in an unannotated region. prettyprinterRaise a hard generic  when the  to   conversion fails. prettyprinter Raise a hard  when the to  4 parser finishes without consuming the full input. Safe-Inferred 389 prettyprinter+Options to influence the layout algorithms.  prettyprinterMaximum number of characters that fit in one line. The layout algorithms will try not to exceed the set limit by inserting line breaks when applicable (e.g. via 1).  prettyprinter9Layouters should not exceed the specified space per line.The  is the number of characters, including whitespace, that fit in a line. A typical value is 80.The  is the ribbon with, i.e. the fraction of the total page width that can be printed on. This allows limiting the length of printable text per line. Values must be between 0 and 1, and 0.4 to 1 is typical.  prettyprinter8Layouters should not introduce line breaks on their own.  prettyprinterThe data type SimpleDocStream represents laid out documents and is used by the display functions.A simplified view is that  = [ ],, and the layout functions pick one of the  s based on which one fits the layout constraints best. This means that  " has all complexity contained in  resolved, making it very easy to convert it to other formats, such as plain text or terminal output.To write your own = to X converter, it is therefore sufficient to convert from  . The Render submodules provide some built-in converters to do so, and helpers to create own ones. prettyprinter is O(n), so we cache it in the  field. prettyprinterInt( = indentation level for the (next) line prettyprinter,Add an annotation to the remaining document. prettyprinter&Remove a previously pushed annotation. prettyprinter Fusion depth parameter, used by V. prettyprinterDo not dive deep into nested documents, fusing mostly concatenations of text nodes together. prettyprinterRecurse into all parts of the , including different layout alternatives, and location-sensitive values such as created by G which cannot be fused before, but only during, the layout process. As a result, the performance cost of using deep fusion is often hard to predict, and depends on the interplay between page layout and document to prettyprint.This value should only be used if profiling shows it is significantly faster than using . prettyprinterOverloaded conversion to .Laws: output should be pretty. :-) prettyprinter,pretty 1 <+> pretty "hello" <+> pretty 1.234 1 hello 1.234 prettyprinter is only used to define the  instance  a =>  [a]#. In normal circumstances only the  function is used.prettyList [1, 23, 456] [1, 23, 456] prettyprinterThe abstract data type  ann represents pretty documents that have been annotated with data of type ann.#More specifically, a value of type  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 as7color information (e.g. when rendering to the terminal)1mouseover 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  is via the  class.)putStrLn (show (vsep ["hello", "world"]))helloworld prettyprinterOccurs when flattening a line. The layouter will reject this document, choosing a more suitable rendering. prettyprinter-The empty document; conceptually the unit of " prettyprinterinvariant: not 'n' prettyprinterInvariants: 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  of  is  O(length)#, we cache it in this constructor.  prettyprinterHard line break! prettyprinterLay out the first , but when flattened (via 3), prefer the second.The layout algorithms work under the assumption that the first alternative is less wide than the flattened second alternative." prettyprinterConcatenation of two documents# prettyprinter(Document indented by a number of columns$ prettyprinterInvariant: 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 3.% prettyprinter*React on the current cursor position, see F& prettyprinter#React on the document's width, see I' prettyprinter(React on the current nesting level, see G( prettyprinter"Add an annotation to the enclosed . Can be used for example to add styling directives or alt texts that can then be used by the renderer.) prettyprinter"Convenience function to convert a able value to a  . If the  does not contain newlines, consider using the more performant *.* prettyprinter"Convenience function to convert a 2able value /that must not contain newlines/ to a  . If there may be newlines, use ) instead.+ prettyprinter(unsafeTextWithoutNewlines s) contains the literal string s.The string must not contain any newline characters, since this is an invariant of the  constructor., prettyprinter The empty document behaves like ( ""), so it has a height of 1. This may lead to surprising behaviour if we expect it to bear no weight inside e.g. B0, where we get an empty line of output from it (parens for visibility only):(vsep ["hello", parens emptyDoc, "world"]hello()worldTogether with , , forms the  .- prettyprinter(- i x) lays out the document x with the current nesting level (indentation of the following lines) increased by i. Negative values are allowed, and decrease the nesting level accordingly.?vsep [nest 4 (vsep ["lorem", "ipsum", "dolor"]), "sit", "amet"]lorem ipsum dolorsitametSee also6 (- relative to current cursor position instead of current nesting level)5/ (set nesting level to current cursor position)79 (increase indentation on the spot, padding with spaces).. prettyprinterThe . document advances to the next line and indents to the current nesting level.3let doc = "lorem ipsum" <> line <> "dolor sit amet"doc lorem ipsumdolor sit amet. behaves like space if the line break is undone by 3: group doclorem ipsum dolor sit amet/ prettyprinter/ is like ., but behaves like ! if the line break is undone by 3 (instead of space).4let doc = "lorem ipsum" <> line' <> "dolor sit amet"doc lorem ipsumdolor sit amet group doclorem ipsumdolor sit amet0 prettyprintersoftline behaves like space8 if the resulting output fits the page, otherwise like ..9Here, we have enough space to put everything in one line:7let doc = "lorem ipsum" <> softline <> "dolor sit amet"putDocW 80 doclorem ipsum dolor sit ametIf we narrow the page to width 10, the layouter produces a line break:putDocW 10 doc lorem ipsumdolor sit amet 0 = 3 . 1 prettyprinter1 is like 0, but behaves like ? if the resulting output does not fit on the page (instead of space). In other words, . is to / how 0 is to 1./With enough space, we get direct concatenation:3let doc = "ThisWord" <> softline' <> "IsWayTooLong"putDocW 80 docThisWordIsWayTooLongIf we narrow the page to width 10, the layouter produces a line break:putDocW 10 docThisWord IsWayTooLong 1 = 3 / 2 prettyprinterA 2 is always% laid out as a line break, even when 3ed or when there is plenty of space. Note that it might still be simply discarded if it is part of a 4 inside a 3.7let doc = "lorem ipsum" <> hardline <> "dolor sit amet"putDocW 1000 doc lorem ipsumdolor sit amet group doc lorem ipsumdolor sit amet3 prettyprinter(3 x) tries laying out x into a single line by removing the contained line breaks; if this does not fit the page, or when a 2 within x# prevents it from being flattened, x" is laid out without any changes.The 3 function is key to layouts that adapt to available space nicely.See B, ., or 48 for examples that are related, or make good use of it.4 prettyprinter By default, (4 x y) renders as x. However when 3ed, y will be preferred, with x# as the fallback for the case when y doesn't fit.let doc = flatAlt "a" "b" putDoc docaputDoc (group doc)bputDocW 0 (group doc)a4 is particularly useful for defining conditional separators such as  softline = 3 (4 2 " ") +let hello = "Hello" <> softline <> "world!"putDocW 12 hello Hello world!putDocW 11 helloHelloworld!Example: Haskell's do-notation7We can use this to render Haskell's do-notation nicely:!let open = flatAlt "" "{ "!let close = flatAlt "" " }"!let separator = flatAlt "" "; "let prettyDo xs = group ("do" <+> align (encloseSep open close separator xs))let statements = ["name:_ <- getArgs", "let greet = \"Hello, \" <> name", "putStrLn greet"]$This is put into a single line with {;} style if it fits: putDocW 80 (prettyDo statements)do { name:_ <- getArgs; let greet = "Hello, " <> name; putStrLn greet }When there is not enough space the statements are broken up into lines nicely: putDocW 10 (prettyDo statements)do name:_ <- getArgs let greet = "Hello, " <> name putStrLn greetNotes"Users should be careful to choose x to be less wide than y. Otherwise, if y turns out not to fit the page, we fall back on an even wider layout:2let ugly = group (flatAlt "even wider" "too wide")putDocW 7 ugly even widerAlso note that 3 will flatten y:1putDoc (group (flatAlt "x" ("y" <> line <> "y")))y y(This also means that an "unflattenable" y' which contains a hard linebreak will never be rendered:5putDoc (group (flatAlt "x" ("y" <> hardline <> "y")))x5 prettyprinter(5 x) lays out the document x with the nesting level set to the current column. It is used for example to implement 6.As an example, we will put a document right above another one, regardless of the current nesting level. Without 5ment, the second line is put simply below everything we've had so far:#"lorem" <+> vsep ["ipsum", "dolor"] lorem ipsumdolor If we add an 5 to the mix, the >*'s contents all start in the same column:+"lorem" <+> align (vsep ["ipsum", "dolor"]) lorem ipsum dolor6 prettyprinter(6 i x) lays out the document x" with a nesting level set to the current column plus i. Negative values are allowed, and decrease the nesting level accordingly.2let doc = reflow "Indenting these words with hang"$putDocW 24 ("prefix" <+> hang 4 doc)prefix Indenting these words with hangThis differs from -, which is based on the current nesting level plus i/. When you're not sure, try the more efficient -) first. In our example, this would yield2let doc = reflow "Indenting these words with nest"$putDocW 24 ("prefix" <+> nest 4 doc)prefix Indenting these words with nest 6 i doc = 5 (- i doc) 7 prettyprinter(7 i x) indents document x by i5 columns, starting from the current cursor position.;let doc = reflow "The indent function indents these words!"%putDocW 24 ("prefix" <> indent 4 doc)prefix The indent function indents these words! 7 i d = 6 i ({i spaces} <> d) 8 prettyprinter(8 l r sep xs) concatenates the documents xs separated by sep), and encloses the resulting document by l and r.>The documents are laid out horizontally if that fits the page:let doc = "list" <+> align (encloseSep lbracket rbracket comma (map pretty [1,20,300,4000]))putDocW 80 doclist [1,20,300,4000]If there is not enough space, then the input is split into lines entry-wise therwise they are laid out vertically, with separators put in the front:putDocW 10 doclist [1 ,20 ,300 ,4000] Note that doc contains an explicit call to 50 so that the list items are aligned vertically.For putting separators at the end of entries instead, have a look at E.9 prettyprinterHaskell-inspired variant of 8% with braces and comma as separator.+let doc = list (map pretty [1,20,300,4000])putDocW 80 doc[1, 20, 300, 4000]putDocW 10 doc[ 1, 20, 300, 4000 ]: prettyprinterHaskell-inspired variant of 8* with parentheses and comma as separator.-let doc = tupled (map pretty [1,20,300,4000])putDocW 80 doc(1, 20, 300, 4000)putDocW 10 doc( 1, 20, 300, 4000 ); prettyprinter(x ; y) concatenates document x and y with a space in between."hello" <+> "world" hello world x ; y = x  space  y < prettyprinter>Concatenate all documents element-wise with a binary function. < _ [] =  < (**) [x,y,z] = x ** y ** z *Multiple convenience definitions based on <& are already predefined, for example: = = < (;) ? = < (\x y -> x  0  y) 1This is also useful to define customized joiners:=concatWith (surround dot) ["Prettyprinter", "Render", "Text"]Prettyprinter.Render.Text= prettyprinter(= xs) concatenates all documents xs horizontally with ;,, i.e. it puts a space between all entries.2let docs = Util.words "lorem ipsum dolor sit amet" hsep docslorem ipsum dolor sit amet= does not introduce line breaks on its own, even when the page is too narrow:putDocW 5 (hsep docs)lorem ipsum dolor sit amet*For automatic line breaks, consider using ? instead.> prettyprinter(> xs) concatenates all documents xs above each other. If a 3$ undoes the line breaks inserted by vsep&, the documents are separated with a space instead.Using > alone yields."prefix" <+> vsep ["text", "to", "lay", "out"] prefix texttolayout3ing a > separates the documents with a space< if it fits the page (and does nothing otherwise). See the @) convenience function for this use case.The 5 function can be used to align the documents under their first element:6"prefix" <+> align (vsep ["text", "to", "lay", "out"]) prefix text to lay outSince 3ing a > is rather common, @ is a built-in for doing that.? prettyprinter(? xs) concatenates the documents xs horizontally with ;. as long as it fits the page, then inserts a .0 and continues doing that for all documents in xs. (. means that if 3(ed, the documents are separated with a space instead of newlines. Use C if you do not want a space.)(Let's print some words to fill the line:let docs = take 20 (cycle ["lorem", "ipsum", "dolor", "sit", "amet"])%putDocW 80 ("Docs:" <+> fillSep docs)Docs: lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor#sit amet lorem ipsum dolor sit amet8The same document, printed at a width of only 40, yields%putDocW 40 ("Docs:" <+> fillSep docs)&Docs: lorem ipsum dolor sit amet lorem&ipsum dolor sit amet lorem ipsum dolor#sit amet lorem ipsum dolor sit amet@ prettyprinter(@ xs) tries laying out the documents xs separated with spaces, and if this does not fit the page, separates them with newlines. This is what differentiates it from >9, which always lays out its contents beneath each other.7let doc = "prefix" <+> sep ["text", "to", "lay", "out"]putDocW 80 docprefix text to lay out>With a narrower layout, the entries are separated by newlines:putDocW 20 doc prefix texttolayout @ = 3 . > A prettyprinter(A xs) concatenates all documents xs horizontally with  (i.e. without any spacing).>It is provided only for consistency, since it is identical to .)let docs = Util.words "lorem ipsum dolor" hcat docsloremipsumdolorB prettyprinter(B xs)' vertically concatenates the documents xs . If it is 3 ed, the line breaks are removed.In other words B is like >0, with newlines removed instead of replaced by spaces.)let docs = Util.words "lorem ipsum dolor" vcat docsloremipsumdolorgroup (vcat docs)loremipsumdolorSince 3ing a B is rather common, D is a built-in shortcut for it.C prettyprinter(C xs) concatenates documents xs horizontally with . as long as it fits the page, then inserts a /0 and continues doing that for all documents in xs. This is similar to how an ordinary word processor lays out the text if you just keep typing after you hit the maximum line length.(/ means that if 3ed, the documents are separated with nothing instead of newlines. See ? if you want a space instead.)Observe the difference between ? and C. ? concatenates the entries spaced when 3ed:let docs = take 20 (cycle (["lorem", "ipsum", "dolor", "sit", "amet"]))0putDocW 40 ("Grouped:" <+> group (fillSep docs))#Grouped: lorem ipsum dolor sit amet&lorem ipsum dolor sit amet lorem ipsum$dolor sit amet lorem ipsum dolor sitametOn the other hand, C) concatenates the entries directly when 3ed:0putDocW 40 ("Grouped:" <+> group (fillCat docs))$Grouped: loremipsumdolorsitametlorem'ipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametD prettyprinter(D xs) tries laying out the documents xs separated with nothing, and if this does not fit the page, separates them with newlines. This is what differentiates it from B9, which always lays out its contents beneath each other.)let docs = Util.words "lorem ipsum dolor"!putDocW 80 ("Docs:" <+> cat docs)Docs: loremipsumdolorWhen there is enough space, the documents are put above one another:!putDocW 10 ("Docs:" <+> cat docs) Docs: loremipsumdolor D = 3 . B E prettyprinter(E p xs) appends p! to all but the last document in xs.let docs = punctuate comma (Util.words "lorem ipsum dolor sit amet")putDocW 80 (hsep docs)lorem, ipsum, dolor, sit, ametThe separators are put at the end of the entries, which we can see if we position the result vertically:putDocW 20 (vsep docs)lorem,ipsum,dolor,sit,ametIf you want put the commas in front of their elements instead of at the end, you should use : or, in general, 8.F prettyprinter:Layout a document depending on which column it starts at. 5 is implemented in terms of F.6column (\l -> "Columns are" <+> pretty l <> "-based.")Columns are 0-based.let doc = "prefix" <+> column (\l -> "| <- column" <+> pretty l)"vsep [indent n doc | n <- [0,4,8]]prefix | <- column 7 prefix | <- column 11 prefix | <- column 15G prettyprinter+Layout a document depending on the current - ing level. 5 is implemented in terms of G.let doc = "prefix" <+> nesting (\l -> brackets ("Nested:" <+> pretty l))"vsep [indent n doc | n <- [0,4,8]]prefix [Nested: 0] prefix [Nested: 4] prefix [Nested: 8]H prettyprinter(H doc f) lays out the document doc<, and makes the column width of it available to a function.let annotate doc = width (brackets doc) (\w -> " <- width:" <+> pretty w)align (vsep (map annotate ["---", "------", indent 3 "---", vsep ["---", indent 4 "---"]]))[---] <- width: 5[------] <- width: 8[ ---] <- width: 8[--- ---] <- width: 8I prettyprinterLayout a document depending on the page width, if one has been specified.let prettyPageWidth (AvailablePerLine l r) = "Width:" <+> pretty l <> ", ribbon fraction:" <+> pretty r=let doc = "prefix" <+> pageWidth (brackets . prettyPageWidth)/putDocW 32 (vsep [indent n doc | n <- [0,4,8]])(prefix [Width: 32, ribbon fraction: 1.0], prefix [Width: 32, ribbon fraction: 1.0]0 prefix [Width: 32, ribbon fraction: 1.0]J prettyprinter(J i x) lays out the document x. It then appends spaces until the width is equal to i. If the width of x) is already larger, nothing is appended.This function is quite useful in practice to output a list of bindings:let types = [("empty","Doc"), ("nest","Int -> Doc -> Doc"), ("fillSep","[Doc] -> Doc")]let ptype (name, tp) = fill 5 (pretty name) <+> "::" <+> pretty tp("let" <+> align (vcat (map ptype types))let empty :: Doc nest :: Int -> Doc -> Doc fillSep :: [Doc] -> DocK prettyprinter(K i x) first lays out the document x. It then appends spaces until the width is equal to i. If the width of x is already larger than i$, the nesting level is increased by i and a line is appended. When we redefine ptype in the example given in J to use K+, we get a useful variation of the output:let types = [("empty","Doc"), ("nest","Int -> Doc -> Doc"), ("fillSep","[Doc] -> Doc")]let ptype (name, tp) = fillBreak 5 (pretty name) <+> "::" <+> pretty tp("let" <+> align (vcat (map ptype types))let empty :: Doc nest :: Int -> Doc -> Doc fillSep :: [Doc] -> DocL prettyprinter(L n one many) is one if n is 1, and many8 otherwise. A typical use case is adding a plural "s".let things = [True]let amount = length thingspretty things <+> "has" <+> pretty amount <+> plural "entry" "entries" amount[True] has 1 entryM prettyprinter(M l r x) encloses document x between documents l and r using .enclose "A" "Z" ""AZ M l r x = l  x  r N prettyprinter(N x l r) surrounds document x with l and r.surround "" "A" "Z"AZ)This is merely an argument reordering of M", but allows for definitions like=concatWith (surround dot) ["Prettyprinter", "Render", "Text"]Prettyprinter.Render.TextO prettyprinterAdd an annotation to a . This annotation can then be used by the renderer to e.g. add color to certain parts of the output. For a full tutorial example on how to use it, see the 3Prettyprinter.Render.Tutorials.StackMachineTutorial or 4Prettyprinter.Render.Tutorials.TreeRenderingTutorial modules.This function is only relevant for custom formats with their own annotations, and not relevant for basic prettyprinting. The predefined renderers, e.g. Prettyprinter.Render.Text., should be enough for the most common needs.P prettyprinterRemove all annotations. Although P) is idempotent with respect to rendering, P . P = P it should not be used without caution, for each invocation traverses the entire contained document. If possible, it is preferrable to unannotate after producing the layout by using S.Q prettyprinterChange the annotation of a ument.Useful in particular to embed documents with one form of annotation in a more generally annotated document. Since this traverses the entire  tree, including parts that are not rendered due to other layouts fitting better, it is preferrable to reannotate after producing the layout by using T.Since Q" has the right type and satisfies 'reAnnotate id = id', it is used to define the  instance of .R prettyprinterChange the annotations of a ument. Individual annotations can be removed, changed, or replaced by multiple ones.)This is a general function that combines P and Q, and it is useful for mapping semantic annotations (such as this is a keyword) to display annotations (such as this is red and underlined), because some backends may not care about certain annotations, while others may.Annotations earlier in the new list will be applied earlier, i.e. returning  [Bold, Green] will result in a bold document that contains green text, and not vice-versa. Since this traverses the entire  tree, including parts that are not rendered due to other layouts fitting better, it is preferrable to reannotate after producing the layout by using U.S prettyprinterRemove all annotations. P for  .T prettyprinter%Change the annotation of a document. Q for  .U prettyprinterChange the annotation of a document to a different annotation, or none at all. R for  .Note that the  version is more flexible, since it allows changing a single annotation to multiple ones. ( # restores this flexibility again.)V prettyprinter(V depth doc) combines text nodes so they can be rendered more efficiently. A fused document is always laid out identical to its unfused version.When laying a ument out to a  , every component of the input is translated directly to the simpler output format. This sometimes yields undesirable chunking when many pieces have been concatenated together. For example"a" <> "b" <> pretty 'c' <> "d"abcd(results in a chain of four entries in a  :, although this is fully equivalent to the tightly packed"abcd" :: Doc annabcdwhich is only a single  $ entry, and can be processed faster.#It is therefore a good idea to run V on concatenations of lots of small strings that are used many times:>let oftenUsed = fuse Shallow ("a" <> "b" <> pretty 'c' <> "d")hsep (replicate 5 oftenUsed)abcd abcd abcd abcd abcdW prettyprinter%Remove all trailing space characters.This has some performance impact, because it does an entire additional pass over the  .No trimming will be done inside annotations, which are considered to contain no (trimmable) whitespace, since the annotation might actually be about the whitespace, for example a renderer that colors the background of trailing whitespace, as e.g. git diff can be configured to do.Historical note: Since v1.7.0, Z and [ avoid producing the trailing whitespace that was the original motivation for creating W. See  0https://github.com/quchen/prettyprinter/pull/139 for some background info.Y prettyprinterThe default layout options, suitable when you just want some output, and don@t particularly care about the details. Used by the  instance, for example.defaultLayoutOptions9LayoutOptions {layoutPageWidth = AvailablePerLine 80 1.0}Z prettyprinter8This is the default layout algorithm, and it is used by , putDoc and hPutDoc.Z commits to rendering something in a certain way if the next element fits the layout constraints; in other words, it has one   element lookahead when rendering. Consider using the smarter, but a bit less performant, [ algorithm if the results seem to run off to the right before having lots of line breaks.[ prettyprinter,A layout algorithm with more lookahead than Z, that introduces line breaks earlier if the content does not (or will not, rather) fit into one line.+Consider the following python-ish document,4let fun x = hang 2 ("fun(" <> softline' <> x) <> ")"let doc = (fun . fun . fun . fun . fun) (align (list ["abcdef", "ghijklm"]))which we@ll be rendering using the following pipeline (where the layout algorithm has been left open):import Data.Text.IO as T import Prettyprinter.Render.Text6let hr = pipe <> pretty (replicate (26-2) '-') <> pipelet go layouter x = (T.putStrLn . renderStrict . layouter (LayoutOptions (AvailablePerLine 26 1))) (vsep [hr, x, hr])If we render this using Z7 with a page width of 26 characters per line, all the fun: calls fit into the first line so they will be put there:go layoutPretty doc|------------------------|fun(fun(fun(fun(fun( [ abcdef" , ghijklm ])))))|------------------------|Note that this exceeds the desired 26 character page width. The same document, rendered with [, fits the layout contstraints:go layoutSmart doc |------------------------|fun( fun( fun( fun( fun( [ abcdef , ghijklm ])))))|------------------------|The key difference between Z and [ is that the latter will check the potential document until it encounters a line with the same indentation or less than the start of the document. Any line encountered earlier is assumed to belong to the same syntactic structure. Z checks only the first line.1Consider for example the question of whether the As fit into the document below: 1 A 2 A 3 A 4 B 5 BZ will check only line 1, ignoring whether e.g. line 2 might already be too wide. By contrast, [. stops only once it reaches line 4, where the B( has the same indentation as the first A.\ prettyprinter(layoutCompact x) lays out the document x without adding any indentation and without preserving annotations. Since no 'pretty' printing is involved, this layouter is very fast. The resulting output contains fewer characters than a prettyprinted version and can be used for output that is read by other programs.let doc = hang 4 (vsep ["lorem", "ipsum", hang 4 (vsep ["dolor", "sit"])])doclorem ipsum dolor sit=let putDocCompact = renderIO System.IO.stdout . layoutCompactputDocCompact docloremipsumdolorsit] prettyprinter Render a   to a , useful to write ' instances based on the prettyprinter.  instance  MyType where  _ = ] . Z Y .  ^ prettyprinter(A utility for producing indentation etc. textSpaces 3" "2This produces much better Core than the equivalent T.replicate n " "(See  2https://github.com/quchen/prettyprinter/issues/131.)` prettyprinterTransform a document based on its annotations, possibly leveraging  effects.a prettyprinter(Collect all annotations from a document.b prettyprinter!Alter the document@s annotations.This instance makes  + more flexible (because it can be used in -polymorphic values), but * is much less readable compared to using  reAnnotateST in code that only works for   anyway. Consider using the latter when the type does not matter.c prettyprinter( doc) prettyprints document doc with Y, ignoring all annotations.d prettyprinter!Alter the document@s annotations.This instance makes + more flexible (because it can be used in -polymorphic values), but * is much less readable compared to using Q in code that only works for  anyway. Consider using the latter when the type does not matter.e prettyprinter  = ,  = A "mappend "hello" "world" :: Doc ann helloworldf prettyprinter x  y = A [x, y] "hello" <> "world" :: Doc ann helloworldg prettyprinterFinding a good example for printing something that does not exist is hard, so here is an example of printing a list full of nothing.pretty ([] :: [Void])[]h prettyprinter(lazy + instance, identical to the strict version)i prettyprinter'Automatically converts all newlines to ..pretty ("hello\nworld" :: Text)helloworld Note that . can be undone by 3:'group (pretty ("hello\nworld" :: Text)) hello world Manually use 2 if you  definitely want newlines.j prettyprinterIgnore  s, print  contents.pretty (Just True)True'braces (pretty (Nothing :: Maybe Bool)){})pretty [Just 1, Nothing, Just 3, Nothing][1, 3]k prettyprinterpretty (123, "hello", False)(123, hello, False)l prettyprinterpretty (123, "hello") (123, hello)m prettyprinterpretty (exp 1 :: Double)2.71828182845904...n prettyprinterpretty (pi :: Float) 3.1415927p prettyprinterpretty (2^123 :: Integer)&10633823966279326983230456482242756608z prettyprinterpretty (123 :: Int)123{ prettyprinter Instead of ( 'n'), consider using .! as a more readable alternative.&pretty 'f' <> pretty 'o' <> pretty 'o'foopretty ("string" :: String)string| prettyprinter pretty TrueTrue} prettyprinter pretty ()()The argument is not used:pretty (error "Strict?" :: ())() prettyprinterpretty [1,2,3] [1, 2, 3] prettyprinterpretty (Identity 1)1 prettyprinterpretty ("hello\nworld")helloworldThis instance uses the  ) instance, and uses the same newline to . conversion. - prettyprinterChange of nesting level4 prettyprinterDefault prettyprinterPreferred when 3ed6 prettyprinterChange of nesting level, relative to the start of the first line7 prettyprinter+Number of spaces to increase indentation by8 prettyprinterleft delimiter prettyprinterright delimiter prettyprinter separator prettyprinterinput documentsE prettyprinterPunctuation, e.g. commaJ prettyprinter6Append spaces until the document is at least this wideK prettyprinter6Append spaces until the document is at least this wideL prettyprinter1 case prettyprinter other casesM prettyprinterL prettyprinterR prettyprinterx prettyprinterLxR  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUV  X YZ\[W]^;6 Safe-Inferred prettyprinter Render a   to a .]] Safe-Inferred] Safe-Inferred8 !"#$%&'( !"#$%&'( Safe-Inferred{('&%$#"!  Safe-Inferred) prettyprinter A variant of  for debugging.Unlike in the  type, the ,  and  constructors don't contain functions but are "sampled" to allow simple inspection with . prettyprinter: (Int -> Diag ann) prettyprinter: (PageWidth -> Diag ann) prettyprinter: (Int -> Diag ann) prettyprinter Convert a " to its diagnostic representation.The functions in the ,  and 4 constructors are sampled with some default values.Use *` to control the function inputs yourself.*diag $ Doc.align (Doc.vcat ["foo", "bar"])Column [(10,Nesting [(10,Cat (Text 3 "foo") (Cat (FlatAlt Line Empty) (Text 3 "bar")))])] prettyprinterCursor positions for the  constructor prettyprinterFor  prettyprinterNesting levels for  Safe-Inferred Safe-Inferred ('&%$#"! )*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^ Safe-InferredT Safe-InferredO prettyprinterWriterT output StateT [style] a!, but with a strict Writer value.The output, type is used to append data chunks to, the style is the member of a stack of styles to model nested styles with. prettyprinter'Simplest possible stack-based renderer./For example, here is a document annotated with (), and the behaviour is to write >>> at the beginning, and <<< at the end of the annotated region:0let doc = "hello" <+> annotate () "world" <> "!"0let sdoc = layoutPretty defaultLayoutOptions docT.putStrLn (renderSimplyDecorated id (\() -> ">>>") (\() -> "<<<") sdoc)hello >>>world<< prettyprinter brackets ""[] prettyprinter braces ""{} prettyprintersquote' prettyprinterdquote" prettyprinterlparen( prettyprinterrparen) prettyprinterlangle< prettyprinterrangle> prettyprinterlbracket[ prettyprinterrbracket] prettyprinterlbrace{ prettyprinterrbrace} prettyprintersemi; prettyprintercolon: prettyprintercomma, prettyprinter"a" <> space <> "b"a bThis is mostly used via ;, "a" <+> "b"a b prettyprinterdot. prettyprinterslash/ prettyprinter backslash\ prettyprinterequals= prettyprinterpipe|Daan Leijen (c) 2000, http://www.cs.uu.nl/~daan Max Bolingbroke (c) 2008, http://blog.omega-prime.co.uk David Luposchainsky (c) 2016, http://github.com/quchen#BSD-style (see the file LICENSE.md)/David Luposchainsky  experimentalportable Safe-Inferred )*,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWYZ[\)*,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUV   YZ\[W  Safe-Inferred38 prettyprinterA  6 is a linked list of different annotated cons cells ( and then some further  ,  and then some further  , @). This format is very suitable as a target for a layout engine, but not very useful for rendering to a structured format such as HTML, where we don@t want to do a lookahead until the end of some markup. These formats benefit from a tree-like structure that explicitly marks its contents as annotated.  is that format. prettyprinter is O(n), so we cache it in the  field. prettyprinterInt( = indentation level for the (next) line prettyprinter Annotate the contained document. prettyprinter/Horizontal concatenation of multiple documents. prettyprinter&Simplest possible tree-based renderer./For example, here is a document annotated with (), and the behaviour is to surround annotated regions with >>> and <<<:0let doc = "hello" <+> annotate () "world" <> "!" ">>>" <> x <> "<<<") stdoc)hello >>>world<< align (vsep ["ipsum dolor", parens "foo bar", "sit amet"]) render doclorem ipsum dolor (foo bar) sit amet prettyprinter( sdoc) takes the output sdoc= from a rendering function and transforms it to strict text. prettyprinter( h sdoc) writes sdoc to the file h.renderIO System.IO.stdout (layoutPretty defaultLayoutOptions "hello\nworld")helloworld%This function is more efficient than  h ( sdoc), since it writes to the handle directly, skipping the intermediate  representation. prettyprinter( doc) prettyprints document doc to standard output. Uses the Y.putDoc ("hello" <+> "world") hello world  =    prettyprinterLike , but instead of using , print to a user-provided handle, e.g. a file or a socket. Uses the Y. main =  filename (h ->  h doc) where doc = B4 ["vertical", "text"] filename = "someFile.txt"  h doc =  h (Z Y doc)   Safe-Inferred! Safe-InferredE )*,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWYZ[\" Safe-Inferred  Safe-Inferred prettyprinter4Double @99-66@ quotes, as used in German typography.putDoc (d9966quotes "")@@ prettyprinter5Double @66-99@ quotes, as used in English typography.putDoc (d6699quotes "")@@ prettyprinter2Single @9-6@ quotes, as used in German typography.putDoc (s96quotes "")@@ prettyprinter3Single @6-9@ quotes, as used in English typography.putDoc (s69quotes "")@@ prettyprinterDouble guillemets, pointing outwards (without adding any spacing).putDoc (dGuillemetsOut "") prettyprinterDouble guillemets, pointing inwards (without adding any spacing).putDoc (dGuillemetsIn "") prettyprinterSingle @guillemets@, pointing outwards (without adding any spacing).putDoc (sGuillemetsOut "")@@ prettyprinterSingle @guillemets@, pointing inwards (without adding any spacing).putDoc (sGuillemetsIn "")@@ prettyprinter Bottom @99@ style double quotes.putDoc b99dquote@ prettyprinterTop @66@ style double quotes.putDoc t66dquote@ prettyprinterTop @99@ style double quotes.putDoc t99dquote@ prettyprinterBottom @9@ style single quote.putDoc b9quote@ prettyprinterTop @66@ style single quote.putDoc t6quote@ prettyprinterTop @9@ style single quote.putDoc t9quote@ prettyprinter Right-pointing double guillemetsputDoc rdGuillemet prettyprinterLeft-pointing double guillemetsputDoc ldGuillemet prettyprinter Right-pointing single guillemetsputDoc rsGuillemet@ prettyprinterLeft-pointing single guillemetsputDoc lsGuillemet@ prettyprinter putDoc bullet@ prettyprinter putDoc endash@ prettyprinter putDoc euroA prettyprinter putDoc cent prettyprinter putDoc yen prettyprinter putDoc pound# Safe-Inferredc Safe-Inferredȑ prettyprinterSplit an input into word-sized s.+putDoc (tupled (words "Lorem ipsum dolor"))(Lorem, ipsum, dolor) prettyprinterInsert soft linebreaks between words, so that text is broken into multiple lines when it exceeds the available width.putDocW 32 (reflow "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididuntut labore et dolore magnaaliqua.  = ? .   prettyprinterRender a document with a certain width. Useful for quick-and-dirty testing of layout behaviour. Used heavily in the doctests of this package, for example.let doc = reflow "Lorem ipsum dolor sit amet, consectetur adipisicing elit"putDocW 20 docLorem ipsum dolor sit amet, consecteturadipisicing elitputDocW 30 docLorem ipsum dolor sit amet,consectetur adipisicing elit$ Safe-Inferred%&'()*+,-../0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~@ABCDEFGHIJKL                                                                                             %%%&%&%&%&%&%%%%&%&%%CC%%)prettyprinter-1.7.1-BauxLiNvN3EiJKyXe93SM PrettyprinterPrettyprinter.Render.Util.PanicPrettyprinter.Internal.TypePrettyprinter.InternalPrettyprinter.Render.StringPrettyprinter.Internal.Debug&Prettyprinter.Render.Util.StackMachinePrettyprinter.Symbols.Ascii'Prettyprinter.Render.Util.SimpleDocTree4Prettyprinter.Render.Tutorials.TreeRenderingTutorial3Prettyprinter.Render.Tutorials.StackMachineTutorialPrettyprinter.Render.TextPrettyprinter.Symbols.UnicodePrettyprinter.UtilSFailSimpleDocStream SimpleDocTree'Data.Text.Prettyprint.Doc.Render.String'Data.Text.Prettyprint.Doc.Internal.Type(Data.Text.Prettyprint.Doc.Internal.Debug"Data.Text.Prettyprint.Doc.Internal+Data.Text.Prettyprint.Doc.Render.Util.Panic2Data.Text.Prettyprint.Doc.Render.Util.StackMachine Data.Textlength3Data.Text.Prettyprint.Doc.Render.Util.SimpleDocTreerenderrenderStackMachineData.Text.Prettyprint.Doc.Render.Tutorials.TreeRenderingTutorial renderTree?Data.Text.Prettyprint.Doc.Render.Tutorials.StackMachineTutorial%Data.Text.Prettyprint.Doc.Render.TextData.Text.Prettyprint.Doc'Data.Text.Prettyprint.Doc.Symbols.Ascii)Data.Text.Prettyprint.Doc.Symbols.UnicodeData.Text.Prettyprint.Doc.UtilbaseGHC.Base<>panicUncaughtFailpanicUnpairedPop"panicSimpleDocTreeConversionFailedpanicInputNotFullyConsumedpanicPeekedEmptypanicPoppedEmpty LayoutOptionslayoutPageWidth PageWidthAvailablePerLine UnboundedSEmptySCharSTextSLineSAnnPushSAnnPop FusionDepthShallowDeepPrettypretty prettyListDocFailEmptyCharTextLineFlatAltCatNestUnionColumn WithPageWidthNesting AnnotatedviaShow unsafeViaShowunsafeTextWithoutNewlinesemptyDocnestlineline'softline softline'hardlinegroupflatAltalignhangindent encloseSeplisttupled<+> concatWithhsepvsepfillSepsephcatvcatfillCatcat punctuatecolumnnestingwidth pageWidthfill fillBreakpluralenclosesurroundannotate unAnnotate reAnnotatealterAnnotations unAnnotateS reAnnotateSalterAnnotationsSfuseremoveTrailingWhitespacedefaultPageWidthdefaultLayoutOptions layoutPretty layoutSmart layoutCompact renderShowS textSpaces$fFunctorFlattenResult$fTraversableSimpleDocStream$fFoldableSimpleDocStream$fFunctorSimpleDocStream $fShowDoc $fFunctorDoc $fMonoidDoc$fSemigroupDoc $fPrettyVoid $fPrettyText $fPrettyText0 $fPrettyMaybe $fPretty(,,) $fPretty(,)$fPrettyDouble $fPrettyFloat$fPrettyNatural$fPrettyInteger$fPrettyWord64$fPrettyWord32$fPrettyWord16 $fPrettyWord8 $fPrettyWord $fPrettyInt64 $fPrettyInt32 $fPrettyInt16 $fPrettyInt8 $fPrettyInt $fPrettyChar $fPrettyBool $fPretty()$fPrettyNonEmpty $fPretty[]$fPrettyIdentity $fPrettyConst $fIsStringDoc$fEqLayoutOptions$fOrdLayoutOptions$fShowLayoutOptions $fGenericDoc $fEqPageWidth$fOrdPageWidth$fShowPageWidth$fEqSimpleDocStream$fOrdSimpleDocStream$fShowSimpleDocStream$fGenericSimpleDocStream$fEqFusionDepth$fOrdFusionDepth$fShowFusionDepth renderStringDiagdiagdiag' $fShowDiag StackMachinerenderSimplyDecoratedrenderSimplyDecoratedA pushStyleunsafePopStyleunsafePeekStyle writeOutputexecStackMachine$fMonadStackMachine$fApplicativeStackMachine$fFunctorStackMachinesquotesdquotesparensanglesbracketsbracessquotedquotelparenrparenlangleranglelbracketrbracketlbracerbracesemicoloncommaspacedotslash backslashequalspipeSTEmptySTCharSTTextSTLineSTAnnSTConcattreeForm unAnnotateST reAnnotateSTalterAnnotationsST$fAlternativeUniqueParser$fMonadFailUniqueParser$fMonadUniqueParser$fApplicativeUniqueParser$fFunctorUniqueParser$fTraversableSimpleDocTree$fFoldableSimpleDocTree$fFunctorSimpleDocTree$fEqSimpleDocTree$fOrdSimpleDocTree$fShowSimpleDocTree$fGenericSimpleDocTree$fEqSimpleDocTok$fOrdSimpleDocTok$fShowSimpleDocTokColorRedGreenBlue SimpleHtmlBoldItalics ParagraphHeadlinebolditalics paragraphheadlinecolorencloseInTagForhtmlTag renderLazy renderStrictrenderIOputDochPutDoc d9966quotes d6699quotes s96quotes s69quotesdGuillemetsOut dGuillemetsInsGuillemetsOut sGuillemetsIn b99dquote t66dquote t99dquoteb9quotet6quotet9quote rdGuillemet ldGuillemet rsGuillemet lsGuillemetbulletendasheurocentyenpoundwordsreflowputDocWGHC.Errerrorghc-prim GHC.TypesIntDouble text-1.2.3.2GHC.ShowShowStringMonoidmemptymconcatFunctorshowShowS showsPrec Applicativefmap GHC.MaybeNothingJustData.Text.InternalData.Text.Internal.BuilderBuilderData.Text.Internal.Lazy Data.Text.IOhPutStrGHC.IO.Handle.FDstdout System.IOwithFile