File: libs-10.html

package info (click to toggle)
hugs 1.4.199801-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 7,220 kB
  • ctags: 5,609
  • sloc: ansic: 32,083; haskell: 12,143; yacc: 949; perl: 823; sh: 602; makefile: 236
file content (77 lines) | stat: -rw-r--r-- 2,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<HTML>
<HEAD>
<TITLE>The Hugs-GHC Extension Libraries: Pretty </TITLE>
</HEAD>
<BODY>
<A HREF="libs-9.html">Previous</A>
Next
<A HREF="libs.html#toc10">Table of Contents</A>
<HR>
<H2><A NAME="s10">10. Pretty </A></H2>


<P>This library contains Simon Peyton Jones' implementation of John
Hughes's pretty printer combinators.</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
module Pretty where
infixl 6 &lt;&gt; 
infixl 6 &lt;+&gt;
infixl 5 $$, $+$
data Doc  -- the Document datatype

-- The primitive Doc values
empty                     :: Doc
text                      :: String   -&gt; Doc 
char                      :: Char     -&gt; Doc
int                       :: Int      -&gt; Doc
integer                   :: Integer  -&gt; Doc
float                     :: Float    -&gt; Doc
double                    :: Double   -&gt; Doc
rational                  :: Rational -&gt; Doc
semi, comma, colon, space, equals              :: Doc
lparen, rparen, lbrack, rbrack, lbrace, rbrace :: Doc
parens, brackets, braces  :: Doc -&gt; Doc 
quotes, doubleQuotes      :: Doc -&gt; Doc

-- Combining Doc values
(&lt;&gt;)   :: Doc -&gt; Doc -&gt; Doc     -- Beside
hcat   :: [Doc] -&gt; Doc          -- List version of &lt;&gt;
(&lt;+&gt;)  :: Doc -&gt; Doc -&gt; Doc     -- Beside, separated by space
hsep   :: [Doc] -&gt; Doc          -- List version of &lt;+&gt;
($$)   :: Doc -&gt; Doc -&gt; Doc     -- Above; if there is no
                                  -- overlap it &quot;dovetails&quot; the two
vcat   :: [Doc] -&gt; Doc          -- List version of $$
cat    :: [Doc] -&gt; Doc          -- Either hcat or vcat
sep    :: [Doc] -&gt; Doc          -- Either hsep or vcat
fcat   :: [Doc] -&gt; Doc          -- ``Paragraph fill'' version of cat
fsep   :: [Doc] -&gt; Doc          -- ``Paragraph fill'' version of sep
nest   :: Int -&gt; Doc -&gt; Doc     -- Nested
hang   :: Doc -&gt; Int -&gt; Doc -&gt; Doc
punctuate :: Doc -&gt; [Doc] -&gt; [Doc]      
-- punctuate p [d1, ... dn] = [d1 &lt;&gt; p, d2 &lt;&gt; p, ... dn-1 &lt;&gt; p, dn]

-- Displaying Doc values
instance Show Doc
render     :: Doc -&gt; String             -- Uses default style
renderStyle  :: Style -&gt; Doc -&gt; String
data Style = Style { lineLength     :: Int,   -- In chars
                       ribbonsPerLine :: Float, -- Ratio of ribbon length
                                                -- to line length
                       mode :: Mode
               }
data Mode = PageMode            -- Normal 
            | ZigZagMode          -- With zig-zag cuts
            | LeftMode            -- No indentation, infinitely long lines
            | OneLineMode         -- All on one line
</PRE>
</CODE></BLOCKQUOTE>
</P>

<HR>
<A HREF="libs-9.html">Previous</A>
Next
<A HREF="libs.html#toc10">Table of Contents</A>
</BODY>
</HTML>