An extra blank line in a vcat in the wl-pprint package
Asked Answered
H

2

6

I use wl-pprint package, because the standard PrettyPrinter lacks functionality. All is good, except an empty doc in a vcat function (the same thing with <$> combinator).

Correct behavior:

import Text.PrettyPrint
> vcat[text "a", empty, text "b"]   
a
b

wl-pprint shows an extra blank line:

import Text.PrettyPrint.Leijen
> vcat[text "a", empty, text "b"]   
a

b

So what can I do? It is imposible to filter vcat list, because there is no Eq instance for Doc.

Hesta answered 18/6, 2012 at 13:33 Comment(1)
looks like the lib could use an isEmpty function, or somesuch thing. Contact the package author, and possibly send him a patch that will work for you.Fayola
H
1

Because I hadn't have any better ideas, I made the following changes in the source

(<$$>) :: Doc -> Doc -> Doc
x <$$> Empty    = x                   -- <<< added
Empty <$$> y    = y                   -- <<< added
x <$$> y        = x <> linebreak <> y
Hesta answered 27/6, 2012 at 13:35 Comment(0)
K
0

define vcatSoft = fold <//>

The docs say "The document (vcat xs) concatenates all documents xs vertically with ().", and looking at <$$>, it says it "concatenates document x and y with a linebreak in between." But notice the next function, <//>, which uses a softbreak instead. And looking at the defn of vcat, it's simply vcat = fold <$$>, so define a function = fold <//>.

Kawasaki answered 18/6, 2012 at 17:27 Comment(2)
This function already exists (fillCat), but it returns “ab” inlineHesta
Argh, I knew I should've tested this. Reading more closely: Although empty has no content, it does have a 'height' of 1 and behaves exactly like (text "") (and is therefore not a unit of <$>).Kawasaki

© 2022 - 2024 — McMap. All rights reserved.