-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Pretty-printing library -- -- This package contains a pretty-printing library, a set of API's that -- provides a way to easily print out text in a consistent format of your -- choosing. This is useful for compilers and related tools. -- -- This library produces more compact outputs than both Wadler-Leijen or -- Hughes-PJ algorithms, at the expense of computational ressources. The -- core API is based on Hughes-PJ, but some combinators of the Leijen API -- are implemented as well. @package pretty-compact @version 2.0 module Text.PrettyPrint.Compact.Core class Monoid d => Layout d text :: Layout d => String -> d flush :: Layout d => d -> d render :: Layout d => d -> String class Layout d => Document d (<|>) :: Document d => d -> d -> d data Doc instance GHC.Classes.Ord Text.PrettyPrint.Compact.Core.M instance GHC.Classes.Eq Text.PrettyPrint.Compact.Core.M instance GHC.Show.Show Text.PrettyPrint.Compact.Core.M instance GHC.Classes.Ord Text.PrettyPrint.Compact.Core.L instance GHC.Classes.Eq Text.PrettyPrint.Compact.Core.L instance GHC.Base.Monoid Text.PrettyPrint.Compact.Core.L instance GHC.Base.Monoid Text.PrettyPrint.Compact.Core.N instance Text.PrettyPrint.Compact.Core.Layout Text.PrettyPrint.Compact.Core.L instance GHC.Base.Monoid Text.PrettyPrint.Compact.Core.M instance Text.PrettyPrint.Compact.Core.Layout Text.PrettyPrint.Compact.Core.M instance Text.PrettyPrint.Compact.Core.Poset Text.PrettyPrint.Compact.Core.M instance GHC.Base.Monoid Text.PrettyPrint.Compact.Core.Doc instance Text.PrettyPrint.Compact.Core.Layout Text.PrettyPrint.Compact.Core.Doc instance Text.PrettyPrint.Compact.Core.Document Text.PrettyPrint.Compact.Core.Doc instance (Text.PrettyPrint.Compact.Core.Layout a, Text.PrettyPrint.Compact.Core.Layout b) => Text.PrettyPrint.Compact.Core.Layout (a, b) instance (Text.PrettyPrint.Compact.Core.Document a, Text.PrettyPrint.Compact.Core.Document b) => Text.PrettyPrint.Compact.Core.Document (a, b) instance Text.PrettyPrint.Compact.Core.Poset a => Text.PrettyPrint.Compact.Core.Poset (a, b) module Text.PrettyPrint.Compact data Doc text :: Layout d => String -> d flush :: Layout d => d -> d char :: Char -> Doc -- | The hang combinator implements hanging indentation. The document -- (hang i x) renders document x with a nesting level -- set to the current column plus i. The following example uses -- hanging indentation for some text: -- --
-- test = hang 4 (fillSep (map text -- (words "the hang combinator indents these words !"))) ---- -- Which lays out on a page with a width of 20 characters as: -- --
-- the hang combinator -- indents these -- words ! ---- -- The hang combinator is implemented as: -- --
-- hang i x = align (nest i x) --hang :: Int -> Doc -> Doc -> Doc -- | The document (enclosure l r sep xs) concatenates the -- documents xs separated by sep and encloses the -- resulting document by l and r. The documents are -- rendered horizontally if that fits the page. Otherwise they are -- aligned vertically. All separators are put in front of the elements. -- For example, the combinator list can be defined with -- enclosure: -- --
-- list xs = enclosure lbracket rbracket comma xs -- test = text "list" <+> (list (map int [10,200,3000])) ---- -- Which is layed out with a page width of 20 as: -- --
-- list [10,200,3000] ---- -- But when the page width is 15, it is layed out as: -- --
-- list [10 -- ,200 -- ,3000] --encloseSep :: Doc -> Doc -> Doc -> [Doc] -> Doc -- | The document (list xs) comma separates the documents -- xs and encloses them in square brackets. The documents are -- rendered horizontally if that fits the page. Otherwise they are -- aligned vertically. All comma separators are put in front of the -- elements. list :: [Doc] -> Doc -- | The document (tupled xs) comma separates the documents -- xs and encloses them in parenthesis. The documents are -- rendered horizontally if that fits the page. Otherwise they are -- aligned vertically. All comma separators are put in front of the -- elements. tupled :: [Doc] -> Doc -- | The document (semiBraces xs) separates the documents -- xs with semi colons and encloses them in braces. The -- documents are rendered horizontally if that fits the page. Otherwise -- they are aligned vertically. All semi colons are put in front of the -- elements. semiBraces :: [Doc] -> Doc -- | The document (x <+> y) concatenates document x -- and y with a space in between. (infixr 6) (<+>) :: Doc -> Doc -> Doc ($$) :: Doc -> Doc -> Doc -- | The document (hsep xs) concatenates all documents xs -- horizontally with (<+>). hsep :: [Doc] -> Doc -- | The document (sep xs) concatenates all documents xs -- either horizontally with (<+>), if it fits the page, or -- vertically with (<$>). sep :: [Doc] -> Doc -- | The document (hcat xs) concatenates all documents xs -- horizontally with (<>). hcat :: [Doc] -> Doc -- | The document (vcat xs) concatenates all documents xs -- vertically with ($$). vcat :: [Doc] -> Doc -- | The document (cat xs) concatenates all documents xs -- either horizontally with (<>), if it fits the page, or -- vertically with (<$$>). -- --
-- cat xs = group (vcat xs) --cat :: [Doc] -> Doc -- | (punctuate p xs) concatenates all documents in xs -- with document p except for the last document. -- --
-- someText = map text ["words","in","a","tuple"] -- test = parens (align (cat (punctuate comma someText))) ---- -- This is layed out on a page width of 20 as: -- --
-- (words,in,a,tuple) ---- -- But when the page width is 15, it is layed out as: -- --
-- (words, -- in, -- a, -- tuple) ---- -- (If you want put the commas in front of their elements instead of at -- the end, you should use tupled or, in general, -- encloseSep.) punctuate :: Doc -> [Doc] -> [Doc] -- | The document (enclose l r x) encloses document x -- between documents l and r using (<>). enclose :: Doc -> Doc -> Doc -> Doc -- | Document (squotes x) encloses document x with single -- quotes "'". squotes :: Doc -> Doc -- | Document (dquotes x) encloses document x with double -- quotes '"'. dquotes :: Doc -> Doc -- | Document (parens x) encloses document x in -- parenthesis, "(" and ")". parens :: Doc -> Doc -- | Document (angles x) encloses document x in angles, -- "<" and ">". angles :: Doc -> Doc -- | Document (braces x) encloses document x in braces, -- "{" and "}". braces :: Doc -> Doc -- | Document (brackets x) encloses document x in square -- brackets, "[" and "]". brackets :: Doc -> Doc -- | The document lparen contains a left parenthesis, "(". lparen :: Doc -- | The document rparen contains a right parenthesis, ")". rparen :: Doc -- | The document langle contains a left angle, "<". langle :: Doc -- | The document rangle contains a right angle, ">". rangle :: Doc -- | The document lbrace contains a left brace, "{". lbrace :: Doc -- | The document rbrace contains a right brace, "}". rbrace :: Doc -- | The document lbracket contains a left square bracket, "[". lbracket :: Doc -- | The document rbracket contains a right square bracket, "]". rbracket :: Doc -- | The document squote contains a single quote, "'". squote :: Doc -- | The document dquote contains a double quote, '"'. dquote :: Doc -- | The document semi contains a semi colon, ";". semi :: Doc -- | The document colon contains a colon, ":". colon :: Doc -- | The document comma contains a comma, ",". comma :: Doc -- | The document (nest i x) renders document x with the -- current indentation level increased by i (See also hang, -- align and indent). -- --
-- nest 2 (text "hello" <$$$> text "world") <$$$> text "!" ---- -- outputs as: -- --
-- hello -- world -- ! --space :: Doc -- | The document dot contains a single dot, ".". dot :: Doc -- | The document backslash contains a back slash, "\". backslash :: Doc -- | The document equals contains an equal sign, "=". equals :: Doc -- | The document (string s) concatenates all characters in -- s using line for newline characters and -- char for all other characters. It is used instead of -- text whenever the text contains newline characters. string :: String -> Doc -- | The document (int i) shows the literal integer i -- using text. int :: Int -> Doc -- | The document (integer i) shows the literal integer i -- using text. integer :: Integer -> Doc -- | The document (float f) shows the literal float f -- using text. float :: Float -> Doc -- | The document (double d) shows the literal double d -- using text. double :: Double -> Doc -- | The document (rational r) shows the literal rational -- r using text. rational :: Rational -> Doc bool :: Bool -> Doc render :: Layout d => d -> String