Text.PrettyPrint.HughesPJ inserting blank lines

Christian Maeder maeder at tzi.de
Wed Feb 2 07:57:35 EST 2005


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


More information about the Libraries mailing list