RE: Text.PrettyPrint.HughesPJ inserting blank lines

I recall that making 'empty' a unit for <> and <+> and $$ was one of my main goals in revising John Hughes's library. I recall also that it got more complicated than I expected, and I didn't feel very satisfied with the result, though it has worked pretty well for years. If anyone wants to peer into the implementation and add combinators along the lines of those below, that's fine with me. Vertical operations should be easier to do than horizontal ones, because the question of where to insert line breaks doesn't arise. Whether the code below does the job, I couldn't say without looking in detail -- and I'm hoping someone else will do that. It's crucial to maintain the property that you can print an arbitrary long document in bounded space. It would be a great service to also add Haddock documentation, please! Simon | -----Original Message----- | From: libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org] On Behalf Of Christian | Maeder | Sent: 02 February 2005 12:58 | To: Tomasz Zielonka | Cc: libraries@haskell.org | Subject: Re: Text.PrettyPrint.HughesPJ inserting blank lines | | Tomasz Zielonka wrote: | > This is ugly: | > | > x $++$ y = (x <> text "") $+$ text "" $+$ (text "" <> y) | > | > However, I don't know if it's OK that (show (empty $++$ empty) == | > "\n\n"). | | I want "empty" to be a unit of $++$ as well, so that | | -- | list version of '($++$)' | vsep :: [Doc] -> Doc | vsep = foldr ($++$) empty | | works. Therefore I suggest: | | -- | vertical composition with a specified number of blank lines | aboveWithNLs :: Int -> Doc -> Doc -> Doc | aboveWithNLs n d1 d2 = if isEmpty d2 then d1 else | if isEmpty d1 then d2 else | d1 $+$ foldr ($+$) d2 (replicate n $ text "") | | -- | vertical composition with one blank line | ($++$) :: Doc -> Doc -> Doc | ($++$) = aboveWithNLs 1 | | Cheers Christian | _______________________________________________ | Libraries mailing list | Libraries@haskell.org | http://www.haskell.org/mailman/listinfo/libraries
participants (1)
-
Simon Peyton-Jones