caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oleg@okmij.org
To: bob.atkey@gmail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] I never succeeded in using Format
Date: 11 Mar 2014 09:32:35 -0000	[thread overview]
Message-ID: <20140311093235.92383.qmail@www1.g3.pair.com> (raw)
In-Reply-To: <CA+aevF_n0T1FQeka029scoXKy2dd+j3RWVeQUp988+UVgL6kmQ@mail.gmail.com>


> Have you compared your implementation to Christian Lindig's 'Strictly Pretty'?:
>    http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.2200
>
> ... 
> A simple optimisation is to precompute this width, as (I think) you
> do. I did this in my simple implementation of Lindig's idea:
>
>    https://github.com/bobatkey/pretty-monospace/blob/master/lib/Pretty.ml
>
> Neither of these implementations are incremental though; both require
> the entire document to be present up front.

Thank you for the reference! I should compare with his and your
implementations.

Our pretty-printer is designed from the outset to be incremental. It
operates on a stream of tokens: text-string, newline, begin-group,
end-group.  It is literally a functional composition of four stream
transformers which annotate the stream tokens and then format them,
outputting chunks of the final text. The formatting is simple if the
begin-group token is annotated with the width of the corresponding
group. The key idea is that we need to know this width only up to the
point: if it exceeds the page width, we don't need to know by how
much. So, computing this annotation requires only a bounded
look-ahead. It is crucial for the performance to use a sequence data
structure with the amortized constant-time addition and removal on
both ends. Standard libraries of Haskell and Clojure luckily provide
such a data structure.



  reply	other threads:[~2014-03-11  9:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06 16:34 Matthieu Dubuget
2014-03-06 16:46 ` Jeremy Yallop
2014-03-06 16:47 ` Benoit Vaugon
2014-03-06 17:02   ` Matthieu Dubuget
2014-03-06 17:06     ` David Sheets
2014-03-06 17:09       ` Matthieu Dubuget
2014-03-06 19:08         ` Martin Jambon
2014-03-07  7:20           ` Raphaël Proust
2014-03-10  0:47             ` oleg
2014-03-10 11:28               ` Bob Atkey
2014-03-11  9:32                 ` oleg [this message]
2014-03-14 10:21                   ` Francois Pottier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140311093235.92383.qmail@www1.g3.pair.com \
    --to=oleg@okmij.org \
    --cc=bob.atkey@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).