A pretty-printing library (fwd)

Fergus Henderson fjh at cs.mu.oz.au
Sat Apr 26 13:06:48 AEST 1997


Hi,

If anyone wants to work on io__pretty_print,
they should check out the following first.

> To: haskell at dcs.gla.ac.uk
> Subject: A pretty-printing library
> Date: Fri, 25 Apr 1997 08:29:28 -0700
> From: Simon L Peyton Jones <simonpj at cse.ogi.edu>
> 
> Folks,
> 
> Many of you will know of John Hughes pretty printing library [1].
> I recently extended it with two new features:
> 
> 	* An "empty document" which is a unit for all the composition
> 	  operators.  In practice this is tremendously useful.
> 
> 	* A "paragraph fill" combinator.
> 
> There are a number of other new features, summarised below.  
> 
> You can find the library on my OGI web page
> 	http://www.cse.ogi.edu/~simonpj
> 
> Please tell me of any bugs you find, or suggestions you have for improving
> it.  Incidentally, I've fixed a rather subtle bug since I first put the
> library on my Web page, so grab the new copy even if you've come across it
> already.
> 
> Simon
> 
> [1]  RJM Hughes "The Design of a Pretty-printing Library", 
>      in Advanced Functional Programming, Johan Jeuring and 
>      Erik Meijer (eds), LNCS 925
> 
> 
> ======================================================================
> Relative to John's original paper, there are the following new features:
> 
> 1.  There's an empty document, "empty".  It's a left and right unit for 
>     both <> and $$, and anywhere in the argument list for
>     sep, hcat, hsep, vcat, fcat etc.
> 
>     It is Really Useful in practice.
> 
> 2.  There is a paragraph-fill combinator, fsep, that's much like sep,
>     only it keeps fitting things on one line until itc can't fit any more.
> 
> 3.  Some random useful extra combinators are provided.  
> 	<+> puts its arguments beside each other with a space between them,
> 	    unless either argument is empty in which case it returns the other
> 
> 	hcat is a list version of <>
> 	hsep is a list version of <+>
> 	vcat is a list version of $$
> 
> 	cat  is behaves like sep,  but it uses <+> for horizontal conposition
> 	fcat is behaves like fsep, but it uses <+> for horizontal conposition
> 
> 	These new ones do the obvious things:
> 		char, semi, comma, colon, space,
> 		parens, brackets, braces, 
> 		quotes, doubleQuotes
> 	
> 4.	The "above" combinator, $$, now overlaps its two arguments if the
> 	last line of the top argument stops before the first line of the second begins.
> 	For example:  text "hi" $$ nest 5 "there"
> 	lays out as
> 			hi   there
> 	rather than
> 			hi
> 			     there
> 
> 	There are two places this is really useful
> 
> 	a) When making labelled blocks, like this:
> 		Left ->   code for left
> 	        Right ->  code for right
> 		LongLongLongLabel ->
> 			  code for longlonglonglabel
> 	   The block is on the same line as the label if the label is
> 	   short, but on the next line otherwise.
> 
> 	b) When laying out lists like this:
> 		[ first
> 		, second
> 		, third
> 		]
> 	   which some people like.  But if the list fits on one line
> 	   you want [first, second, third].  You can't do this with
> 	   John's original combinators, but it's quite easy with the
> 	   new $$.
> 
> 	The combinator $+$ gives the original "never-overlap" behaviour.
> 
> 5.	Several different renderers are provided:
> 		* a standard one
> 		* one that uses cut-marks to avoid deeply-nested documents 
> 			simply piling up in the right-hand margin
> 		* one that ignores indentation (fewer chars output; good for machines)
> 		* one that ignores indentation and newlines (ditto, only more so)
> 
> 6.	Numerous implementation tidy-ups
> 	Use of unboxed data types to speed up the implementation
> 
> 
> 


-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list