PPrint Library ReferenceSynopsisnamespace PPrint [<Sealed; NoEquality; NoComparison>] type Doc = static member (<^>): Doc * Doc -> Doc static member (<+>): Doc * Doc -> Doc static member (<.>): Doc * Doc -> Doc static member (</>): Doc * Doc -> Doc static member (<..>): Doc * Doc -> Doc static member (<//>): Doc * Doc -> Doc [<AutoOpen>] module PPrint = Descriptionnamespace PPrint PPrint is a pretty printing combinator library for text documents that can be rendered to a desired maximum width. PPrint is based on Wadler's and Leijen's work. Philip Wadler's article ''A prettier printer'' is a good introduction to the motivation and basic usage of this library. Daan Leijen's document ''PPrint, a prettier printer'' provides motivation for several additional primitives like [<Sealed; NoEquality; NoComparison>] type Doc = Represents a document that can be rendered to a given maximum width. static member (<^>): Doc * Doc -> Doc Note: This is the same as the operator static member (<+>): Doc * Doc -> Doc Concatenates the given documents with a static member (<.>): Doc * Doc -> Doc Concatenates the given documents with a For example txt "a" <.> txt "b" renders as a b and txt "a" <.> txt "b" |> group renders as a b Note: In the original Haskell libraries, the symbol <$> was used for this operation, but it is not a legal symbol in F#. static member (</>): Doc * Doc -> Doc Concatenates the given documents with a static member (<..>): Doc * Doc -> Doc Concatenates the given documents with a For example txt "a" <..> txt "b" renders as a b and txt "a" <..> txt "b" |> group renders as ab static member (<//>): Doc * Doc -> Doc [<AutoOpen>] module PPrint = Operations on pretty print documents. [<AbstractClass>] type Actions = Output actions. abstract Line: unit -> unit Called to output a newline. default Line: unit -> unit Default calls abstract User: obj -> unit Called for each user attribute within the document. default User: obj -> unit Default does nothing. abstract Write: string -> unit Called to write a string of characters. val outputWithActions: Actions -> maxCols: option<int> -> doc: Doc -> unit Outputs the document using the given output actions. val outputWithFun: write: (string -> unit) -> maxCols: option<int> -> doc: Doc -> unit Outputs the document using the given output function. val outputToWriter: writer: TextWriter -> maxCols: option<int> -> doc: Doc -> unit Outputs the document using the given text writer. val render: maxCols: option<int> -> doc: Doc -> string Renders the document as a string. val empty: Doc val chr: char -> Doc val txt: string -> Doc val fmt: Printf.StringFormat<'a, Doc> -> 'a val nest: numCols: int -> (Doc -> Doc) For example [txt "x"; txt "y"; txt "z"] |> punctuate comma |> vsep |> parens |> nest 1 renders as (x, y, z) Note that in order for val nestBy: prefix: string -> Doc -> Doc For example [txt "a"; txt "b"; txt "c"] |> vsep |> nestBy " * " |> enclose (txt "(* ", line <^> txt " *)") renders as (* a * b * c *) val line: Doc Advances to the next line and indents, unless undone by For example [txt "a"; line; txt "b"] |> hcat |> nest 2 renders as a b while [txt "a"; line; txt "b"] |> hcat |> nest 2 |> group renders as a b val linebreak: Doc Advances to the next line and indents, unless undone by For example [txt "a"; linebreak; txt "b"] |> hcat |> nest 2 renders as a b while [txt "a"; linebreak; txt "b"] |> hcat |> nest 2 |> group renders as ab val group: Doc -> Doc Used to specify alternative layouts. For example txt "a" <.> txt "b" renders as a b while txt "a" <.> txt "b" |> group renders as a b except when it wouldn't fit within the desired number of columns. val gnest: numCols: int -> (Doc -> Doc) val choice: wide: Doc -> narrow: Doc -> Doc Used to specify alternative documents. The This combinator is not available in the original Haskell libraries. It allows one to create documents whose rendering may not produce optimal or easily predictable results. Nevertheless, careful use of this combinator can produce useful results. The initial use case for this combinator was to format Standard ML string literals so that they are either formatted onto a single line or onto multiple lines using line continuation characters. For example, given let wide = txt "\\\"a\\nb\\nc\\\"" let narrow = vsep [txt "\"a\\n\""; txt "\"b\\n\""; txt "\"c\""] then choice wide narrow renders as the wide version "a\nb\nc" when it fits and as the narrow version "a\n" "b\n" "c" when the wide version does not fit. val delay: (unit -> Doc) -> Doc Creates a lazily computed document. Note: This is primarily useful for specifying the narrow alternative to val softline: Doc val softbreak: Doc val user: obj -> Doc val column: (int -> Doc) -> Doc val nesting: (int -> Doc) -> Doc val indent: int -> Doc -> Doc val hang: int -> Doc -> Doc val align: Doc -> Doc For example txt "foo" <^> ([txt "bar"; txt "baz"; txt "foobar"] |> punctuate comma |> vsep |> align |> parens) renders as foo(bar, baz, foobar) val width: Doc -> (int -> Doc) -> Doc For example width <| txt "foo" <| fun n -> [txt "bar"; txt "baz"; txt "foobar"] |> punctuate comma |> vsep |> parens |> nest (n+1) renders to foo(bar, baz, foobar) Note that val fillBreak: width: int -> Doc -> Doc val fill: width: int -> Doc -> Doc val joinSep: Doc -> seq<Doc> -> Doc val joinWith: (Doc -> Doc -> Doc) -> seq<Doc> -> Doc Concatenate a sequence of documents using the given binary operator. val sep: seq<Doc> -> Doc val cat: seq<Doc> -> Doc val punctuate: punc: Doc -> docs: seq<Doc> -> seq<Doc> For example [txt "a"; txt "b"; txt "c"] |> punctuate comma |> hsep renders to a, b, c val hsep: seq<Doc> -> Doc val vsep: seq<Doc> -> Doc val fillSep: seq<Doc> -> Doc Concatenates the documents using val hcat: seq<Doc> -> Doc val vcat: seq<Doc> -> Doc Concatenates the documents using val fillCat: seq<Doc> -> Doc Concatenates the documents using val enclose: Doc * Doc -> Doc -> Doc val squotes: Doc -> Doc val dquotes: Doc -> Doc val parens: Doc -> Doc val angles: Doc -> Doc val braces: Doc -> Doc val brackets: Doc -> Doc val lrsquote: Doc * Doc val lrdquote: Doc * Doc val lrparen: Doc * Doc val lrangle: Doc * Doc val lrbrace: Doc * Doc val lrbracket: Doc * Doc val lparen: Doc Equivalent to val rparen: Doc Equivalent to val langle: Doc Equivalent to val rangle: Doc Equivalent to val lbrace: Doc Equivalent to val rbrace: Doc Equivalent to val lbracket: Doc Equivalent to val rbracket: Doc Equivalent to val squote: Doc Equivalent to val dquote: Doc Equivalent to val semi: Doc Equivalent to val colon: Doc Equivalent to val comma: Doc Equivalent to val space: Doc Equivalent to val dot: Doc Equivalent to val backslash: Doc Equivalent to val equals: Doc Equivalent to |