Is there a pretty printing (or showing) abstraction in Haskell?

我与影子孤独终老i 提交于 2019-12-06 04:33:52

Note that I'm not asking for something that provides elaborate pretty printing and formatting functionality (I see several packages that do that)

There's a reason for that. The people who wrote those elaborate libraries did so because they couldn't get the job done with something simple. You've already hinted at some of the complexity by offering two different methods that may our may not do the same thing, with no guidance about which to use when.

On the positive side, I wouldn't worry too much about read. Focus on Show instances that (possibly with GHC extensions) can give you code to cut and paste into your programs.

I just did a Hoogle search for a -> String and found the Language.Haskell.Pretty module.

The module defines three simple functions:

prettyPrintStyleMode :: Pretty a => Style -> PPHsMode -> a -> String
pretty-print with a given style and mode.

prettyPrintWithMode :: Pretty a => PPHsMode -> a -> String
pretty-print with the default style and a given mode.

prettyPrint :: Pretty a => a -> String
pretty-print with the default style and defaultMode.

The whole typeclass seems to be a bit more complex than what you have asked for, but maybe it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!