Portability  portable 

Stability  provisional 
Maintainer  andygill@ku.edu 
John Hughes's and Simon Peyton Jones's Pretty Printer Combinators
Based on The Design of a Prettyprinting Library in Advanced Functional Programming, Johan Jeuring and Erik Meijer (eds), LNCS 925 http://www.cs.chalmers.se/~rjmh/Papers/pretty.ps
Heavily modified by Simon Peyton Jones, Dec 96
Marking added by Andy Gill, Oct 08.
 type Doc = MDoc ()
 data MDoc a
 char :: Char > MDoc a
 text :: String > MDoc a
 ptext :: String > MDoc a
 int :: Int > MDoc a
 integer :: Integer > MDoc a
 float :: Float > MDoc a
 double :: Double > MDoc a
 rational :: Rational > MDoc a
 semi :: MDoc a
 comma :: MDoc a
 colon :: MDoc a
 space :: MDoc a
 equals :: MDoc a
 lparen :: MDoc a
 rparen :: MDoc a
 lbrack :: MDoc a
 rbrack :: MDoc a
 lbrace :: MDoc a
 rbrace :: MDoc a
 parens :: MDoc a > MDoc a
 brackets :: MDoc a > MDoc a
 braces :: MDoc a > MDoc a
 quotes :: MDoc a > MDoc a
 doubleQuotes :: MDoc a > MDoc a
 empty :: MDoc a
 (<>) :: MDoc a > MDoc a > MDoc a
 (<+>) :: MDoc a > MDoc a > MDoc a
 hcat :: [MDoc a] > MDoc a
 hsep :: [MDoc a] > MDoc a
 ($$) :: MDoc a > MDoc a > MDoc a
 ($+$) :: MDoc a > MDoc a > MDoc a
 vcat :: [MDoc a] > MDoc a
 sep :: [MDoc a] > MDoc a
 cat :: [MDoc a] > MDoc a
 fsep :: [MDoc a] > MDoc a
 fcat :: [MDoc a] > MDoc a
 nest :: Int > MDoc a > MDoc a
 hang :: MDoc a > Int > MDoc a > MDoc a
 punctuate :: MDoc a > [MDoc a] > [MDoc a]
 isEmpty :: MDoc a > Bool
 render :: MDoc a > String
 data Style = Style {
 mode :: Mode
 lineLength :: Int
 ribbonsPerLine :: Float
 style :: Style
 renderStyle :: Style > MDoc a > String
 fullRender :: Mode > Int > Float > (TextDetails b > a > a) > a > MDoc b > a
 data Mode
 = PageMode
  ZigZagMode
  LeftMode
  OneLineMode
 data TextDetails a
 mark :: a > MDoc a
The document type
Constructing documents
Converting values into documents
Simple derived documents
Wrapping documents in delimiters
doubleQuotes :: MDoc a > MDoc aSource
Wrap document in "..."
Combining documents
($$) :: MDoc a > MDoc a > MDoc aSource
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
nest :: Int > MDoc a > MDoc aSource
Nest (or indent) a document by a given number of positions
(which may also be negative). nest
satisfies the laws:
nest
0 x = xnest
k (nest
k' x) =nest
(k+k') xnest
k (x<>
y) =nest
k z<>
nest
k ynest
k (x$$
y) =nest
k x$$
nest
k ynest
kempty
=empty

x
, if<>
nest
k y = x<>
yx
nonempty
The side condition on the last law is needed because
empty
is a left identity for <>
.
punctuate :: MDoc a > [MDoc a] > [MDoc a]Source
punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn1 <> p, dn]
Predicates on documents
Rendering documents
Default rendering
Rendering with a particular style
A rendering style.
Style  

renderStyle :: Style > MDoc a > StringSource
Render the document as a string using a specified style.
General rendering
:: Mode  Rendering mode 
> Int  Line length 
> Float  Ribbons per line 
> (TextDetails b > a > a)  What to do with text 
> a  What to do at the end 
> MDoc b  The document 
> a  Result 
The general rendering interface.
Rendering mode.
PageMode  Normal 
ZigZagMode  With zigzag cuts 
LeftMode  No indentation, infinitely long lines 
OneLineMode  All on one line 