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: import Data.PrettyPrint tree2doc Leaf = text "Leaf" tree2doc (Bin x l r) = text "Bin" $$ nest 2 (text (show x) $$ tree2doc l $$ tree2doc r) showTree = render . tree2doc /Johan 2012/3/13 Johan Tibell <johan.tibell@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? Example:
Given
data Tree a = Leaf | Bin Int a (Tree a) (Tree a)
and
value = Bin 1 (Bin 2 Leaf Leaf) (Bin 3 Leaf Leaf)
draw as
Bin 1 Bin 2 Leaf Leaf Bin 3 Leaf Leaf
Cheers, Johan
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe