wl-pprint 包中 vcat 中的额外空行

use*_*768 5 haskell pretty-print

我使用wl-pprint包,因为标准的 PrettyPrinter 缺乏功能。一切都很好,除了vcat函数中的空文档(与<$>组合器相同)。

正确行为:

import Text.PrettyPrint
> vcat[text "a", empty, text "b"]   
a
b
Run Code Online (Sandbox Code Playgroud)

wl-pprint 显示一个额外的空行:

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

b
Run Code Online (Sandbox Code Playgroud)

那我能做什么?这是IMPOSIBLE进行筛选VCAT列表中,因为没有Eq为实例Doc

use*_*768 1

因为我没有更好的想法,所以我在源码中做了以下修改

(<$$>) :: Doc -> Doc -> Doc
x <$$> Empty    = x                   -- <<< added
Empty <$$> y    = y                   -- <<< added
x <$$> y        = x <> linebreak <> y
Run Code Online (Sandbox Code Playgroud)