gpt4 book ai didi

haskell - 如何漂亮地打印记录类型?

转载 作者:行者123 更新时间:2023-12-01 07:34:25 25 4
gpt4 key购买 nike

给定像 Example {a = "a", b = "b", c = "c"} 这样的记录我怎样才能漂亮地打印任意 像这样的记录类型使其更易于阅读(更人性化)?
像:

Example {
a = "a"
, b = "b"
, c = "c"
}
将是理想的。
我试过 pPrint来自 pretty-show包,但这似乎与 show 的输出没有任何不同.

最佳答案

这可以通过以下方式实现: pretty-simple :

ghci> import Text.Pretty.Simple (pPrint)
ghci> data Example = Example { a, b, c :: String } deriving Show
ghci> pPrint Example {a = "a", b = "b", c = "c"}
Example
{ a = "a"
, b = "b"
, c = "c"
}

关于haskell - 如何漂亮地打印记录类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45265015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com