[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / docs / libraries / Pretty.sgml
1 <sect> <idx/Pretty/
2 <label id="sec:Pretty">
3 <p>
4
5 This library contains Simon Peyton Jones' implementation of John
6 Hughes's pretty printer combinators.
7
8 <tscreen><verb>
9 module Pretty where
10 infixl 6 <> 
11 infixl 6 <+>
12 infixl 5 $$, $+$
13 data Doc  -- the Document datatype
14
15 -- The primitive Doc values
16 empty                     :: Doc
17 text                      :: String   -> Doc 
18 char                      :: Char     -> Doc
19 int                       :: Int      -> Doc
20 integer                   :: Integer  -> Doc
21 float                     :: Float    -> Doc
22 double                    :: Double   -> Doc
23 rational                  :: Rational -> Doc
24 semi, comma, colon, space, equals              :: Doc
25 lparen, rparen, lbrack, rbrack, lbrace, rbrace :: Doc
26 parens, brackets, braces  :: Doc -> Doc 
27 quotes, doubleQuotes      :: Doc -> Doc
28
29 -- Combining Doc values
30 (<>)   :: Doc -> Doc -> Doc     -- Beside
31 hcat   :: [Doc] -> Doc          -- List version of <>
32 (<+>)  :: Doc -> Doc -> Doc     -- Beside, separated by space
33 hsep   :: [Doc] -> Doc          -- List version of <+>
34 ($$)   :: Doc -> Doc -> Doc     -- Above; if there is no
35                                   -- overlap it "dovetails" the two
36 vcat   :: [Doc] -> Doc          -- List version of $$
37 cat    :: [Doc] -> Doc          -- Either hcat or vcat
38 sep    :: [Doc] -> Doc          -- Either hsep or vcat
39 fcat   :: [Doc] -> Doc          -- ``Paragraph fill'' version of cat
40 fsep   :: [Doc] -> Doc          -- ``Paragraph fill'' version of sep
41 nest   :: Int -> Doc -> Doc     -- Nested
42 hang   :: Doc -> Int -> Doc -> Doc
43 punctuate :: Doc -> [Doc] -> [Doc]      
44 -- punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]
45
46 -- Displaying Doc values
47 instance Show Doc
48 render     :: Doc -> String             -- Uses default style
49 renderStyle  :: Style -> Doc -> String
50 data Style = Style { lineLength     :: Int,   -- In chars
51                        ribbonsPerLine :: Float, -- Ratio of ribbon length
52                                                 -- to line length
53                        mode :: Mode
54                }
55 data Mode = PageMode            -- Normal 
56             | ZigZagMode          -- With zig-zag cuts
57             | LeftMode            -- No indentation, infinitely long lines
58             | OneLineMode         -- All on one line
59 </verb></tscreen>