最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

haskell - Pretty print only top n levels of a data structure - Stack Overflow

programmeradmin0浏览0评论

I have some data structure which are several levels deep and produce extremely long and skinny pretty printed output. It would be desirable, if only the first level (generally n levels) would prettyprint and the rest shown in the regular compact format.

I looked at the various pretty-printer on hackage, but could not find one with a functionality to pretty-print structured records up to a specified depth. Is there such a tool or how can it be constructed?

I have some data structure which are several levels deep and produce extremely long and skinny pretty printed output. It would be desirable, if only the first level (generally n levels) would prettyprint and the rest shown in the regular compact format.

I looked at the various pretty-printer on hackage, but could not find one with a functionality to pretty-print structured records up to a specified depth. Is there such a tool or how can it be constructed?

Share Improve this question asked Feb 3 at 21:56 user855443user855443 2,9485 gold badges32 silver badges45 bronze badges 2
  • I recall an approach named "scrap your boilerplate" that could (I guess?) in principle be used to this task. It's not straightforward to learn though. I wonder if there are more modern simpler alternatives nowadays. – chi Commented Feb 3 at 23:27
  • You can always hand-roll your show instance? (recursively passing down the nesting level and decreasing it by one each time) – mb21 Commented Feb 4 at 10:33
Add a comment  | 

1 Answer 1

Reset to default 0

One possible line of attack: look at prettyprinter. It renders documents to an intermediate form called SimpleDocStream. So you might try writing a renderer which either counts the stack depth or limits the indent width. Not exactly what you asked for, but something like that sounds like it would solve your problem.

发布评论

评论列表(0)

  1. 暂无评论