Haskell Pretty Printing - 无障碍、实用的图书馆

Haskell Pretty Printing - Accessible, practical library

假设我有 [("bird",3,44),("cat",534,3)] :: [(String,Int,Int)]。获得漂亮打印结果的最简单方法是什么,la:

bird    3   44
cat   534    3

似乎有很多 Haskell 漂亮的打印库,但没有明确的最爱,也没有太多示例。

大多数漂亮的打印库都关注替代布局(巧妙地选择何时添加换行符等)。对于这样的事情,使用 boxes:

import Text.PrettyPrint.Boxes
import Data.List
table = [("bird",3,44),("cat",534,3)] :: [(String,Int,Int)]
cols = transpose [ [ animal, show n, show m ] | (animal, n, m) <- table ]
rendered = render . hsep 2 left . map (vcat left . map text) $ cols
putStr rendered

输出:

bird  3    44
cat   534  3