A pretty printer library in Haskell
Version 3.0, 28 May 1997

Version 3.0 adds new exports and fixes a bad performance bug. See comments at the start of the source code.

I have now bitten the bullet and made an "industrial strength" (I hope) pretty printing library in Haskell, based on John Hughes's paper "The Design of a Pretty-printing Library" (in Advanced Functional Programming, Johan Jeuring and Erik Meijer (eds), LNCS 925).

In this zip file are:

Please do try it out, and give me feedback about

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. (John identified the lack of an empty document as a shortcoming in his paper, but couldn't see how to fit it into the algebra.)

  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.

  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
    
    The combinator $+$ gives the original "never-overlap" behaviour.

  5. Several different renderers are provided:

  6. Numerous implementation tidy-ups, plus (for GHC) the use of unboxed data types to speed up the implementation

Simon Peyton Jones, simonpj@dcs.gla.ac.uk