[Haskell-cafe] Prettier pretty-printing of data types?
holmisen at gmail.com
Wed Mar 14 07:54:37 CET 2012
I guess you want an automatically derived show that indents, but if
you don't mind defining you own, Data.PrettyPrint is really nice.
Here is an example that produces roughly the same as your example:
tree2doc Leaf = text "Leaf"
tree2doc (Bin x l r) =
text "Bin" $$
nest 2 (text (show x) $$
tree2doc l $$
showTree = render . tree2doc
2012/3/13 Johan Tibell <johan.tibell at gmail.com>:
> Hi all,
> The derived Show instance is useful, but I sometimes wish for
> something that's easier to read for big data types. Does anyone have
> an implementation of show that draws things in a hierarchical manner?
> data Tree a = Leaf | Bin Int a (Tree a) (Tree a)
> value = Bin 1 (Bin 2 Leaf Leaf) (Bin 3 Leaf Leaf)
> draw as
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe