[m-dev.] Contribution: Pretty Printing Library

Ralph Becket rbeck at microsoft.com
Tue Apr 11 22:35:14 AEST 2000


Hi Mark,

I've made a few small changes to pprint.m - mostly cosmetic internal
and one or two extra useful combinators.  I've got a nice little
arbitrary term pretty printer knocked up (although it'll need some
tweaking to handle the dodgy case of types with user-defined
equality on them).  It doesn't module-qualify constructor names
(a good thing, IMHO).  It will also probably need some sort of
depth limit (easy).

:- func to_doc(T) = doc.

to_doc(X) =
    ( if Arity = 0 then
        text(Name)
      else
        text(Name) `<>`
        parentheses(
            group(
                nest(2, line `<>` separated(id, comma_space_line, Args))
`<>`
                line
            )
        )
    )
:-
    deconstruct(X, Name, Arity, UnivArgs),
    Args = list__map(( func(UnivArg) = to_doc(univ_value(UnivArg)) ),
UnivArgs).

The only problem is that it only works with debugging turned on!  
I've submitted a bug report and Fergus has suggested trying a more
recent rotd.  I'll let you know how I get on when the build
finishes (some time next year...)

Cheers,

Ralph
--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 

> -----Original Message-----
> From: Mark Anthony BROWN [mailto:dougl at cs.mu.OZ.AU]
> Sent: 10 April 2000 08:46
> To: mercury-developers at cs.mu.OZ.AU
> Subject: Re: [m-dev.] Contribution: Pretty Printing Library
> 
> 
> Hi Ralph,
> 
> I have briefly looked over the code; it looks great!
> A pretty printer is sorely needed (by the mdb browser, atleast).
> I'll review the code in the next couple of days---this is to
> let you know that a review is on the way.
> 
> Cheers,
> Mark.
> 
> Ralph Becket writes:
> > 
> > I've knocked up a pretty printing library based on Philip Wadler's
> > paper "A Prettier Printer", which is optimal (doesn't overrun line
> > widths where possible), bounded* (the pp only needs to look ahead
> > k characters to make a formatting decision) and the composition
> > algebra is much simpler than Hughes'.  Note that Hughes' pp is
> > optimal, but not bounded.
> > 
> > This library is released under the LGPL.
> > 
> > Ralph
> > 
> > * Run-time would be too if the implementation were lazy - 
> I'm waiting 
> > for Tyson to deliver that for us :)  I haven't noticed any 
> performance
> > problems in practice...
> > 
> 
> -- 
> Mark Brown, PhD student            )O+  |  "Another of 
> Fortran's breakthroughs
> (m.brown at cs.mu.oz.au)                   |  was the GOTO 
> statement, which was...
> Dept. of Computer Science and Software  |  uniquely simple 
> and understandable"
> Engineering, University of Melbourne    |              -- IEEE, 1994
> --------------------------------------------------------------
> ------------
> mercury-developers mailing list
> Post messages to:       mercury-developers at cs.mu.oz.au
> Administrative Queries: owner-mercury-developers at cs.mu.oz.au
> Subscriptions:          mercury-developers-request at cs.mu.oz.au
> --------------------------------------------------------------
> ------------
> 
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list