[m-dev.] User-controlled pretty-printing

Ralph Becket rafe at csse.unimelb.edu.au
Thu Dec 14 09:44:15 AEDT 2006

Recap: I suggested that we could add support for user-defined term
pretty-printing to mdb by allowing programs to provide their own
pretty printers for various types (e.g., for lists, maps, arrays,
etc.)  Each pretty printer would take a univ and some control parameters
(e.g., to control how much of the term is to be printed) and either
succeed, returning a pprint.doc, or fail, if the value contained in the
univ has the wrong type or form.  Zoltan pointed out that we want rich
control over what is printed and also need a sensible mechanism for
navigating through abstract types (e.g., we don't want to have to
specify a path through a 234-tree when looking for a particular entry in
a map).

So, what we want is:

- the ability to navigate to a subterm using an abstract address
  e.g., go to the "3rd list item" rather than navigating through cons
  cells with "2/2/2/1";

- the ability to specify how certain terms are printed
  e.g., "print only the first and second fields of `foo/7' terms".

These appear to be orthogonal issues to me, but both can be handled by
"supply your own" mechanism: one for converting navigation addresses
from abstract ("3rd list item") to concrete ("2/2/2/1"), and one for
pretty printing.

With regards to rich pretty printing, I think we can handle the complex
cases (e.g., "print only the first and second fields of `foo/7' terms")
by simply pushing specialised pretty printers on to the pretty printer
list and just have a default mechanism for the other cases (e.g.,
limiting printing depth as we do now).

It would be good to hear if anyone has any objections or useful comments
before I go further with this.

-- Ralph
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au

More information about the developers mailing list