【发布时间】:2012-11-10 09:16:11
【问题描述】:
我有一台这样漂亮的打印机:
somefun = text "woo" $+$ nest 4 (text "nested text") $+$ text "text without indent"
fun = text "------" $+$ somefun
我想要的是打印这个:
------ woo
nested text
text without indent
但它会打印:
------
woo
nested text
text without indent
我可以理解为什么会这样打印,但是我无法按照自己的意愿去做。我找到的一种解决方案是:
somefun p = p <+> text "woo" $+$ nest 4 (text "nested text") $+$ text "text without indent"
fun = somefun (text "------")
也就是说,我正在传递我希望下一个 Doc 的缩进所基于的 Doc。这解决了我的问题,但我正在寻找更好的方法来做到这一点。
【问题讨论】:
-
我不认为有更好的方法,
somefun是Doc,这被认为是一个块,你不能在事后只拔出第一行然后改变它。
标签: haskell pretty-print