Tommy Thorn wrote:

> In an attempt to gather experience with Philip Wadlers pretty printing
> combinators, I converted a semi big pretty printer to his pretty
> printing.
>
> > punctuate sep []     = nil
> > punctuate sep [x]    = x
> > punctuate sep (x:xs) = x <> sep <> punctuate sep xs
>
> > vcat                 = punctuate line
> > sep x                = group (vcat x)
>

  Incidentally, the above def of `sep' doesn't match Hughes' in an important
way.  Consider:

    sep [ text "hi", text "bye" $$ text "bye" ]

If we lay this out using Hughes' combinators with a large width, we get

    hi
    bye
    bye

while with the above def, we get:

    hi bye bye

The problem is that, while Hughes' `sep' only flattens the newlines inserted
between each element, `group' flattens everything in its scope.  Further,
Hughes evidently recognizes that any break from a flat layout should result in
a vertical layout.  We can partially fix the def of `sep':

    sep x = punctuate (group line) x

This gives us the questionable:

    hi bye
    bye

Hughes `sep' seems pretty well-behaved in this circumstance, and I'm not sure
how to recapture that using Wadler-style combinators.

--Jeff


Reply via email to