Haskell -- easier to read show function? (for debugging)

Viewed 1703

I'm looking for a function like show that produces more readable output. It certainly doesn't have to work on all classes. I searched "haskell pretty print" on Google, but that seems to produce compiler source code printers. Debugging stuff like the following (newlines inserted manually for stackoverflow formatting) is difficult!

(fromList [(Ref {name = "phi", lenRef = 4},fromList [CompNode {val = 1, ident = CNId {uid =     4,
 zone = 0}, deps = []},CompNode {val = 2, ident = CNId {uid = 5, zone = 0}, deps = []},CompNode 
{val = 3, ident = CNId {uid = 6, zone = 0}, deps = []},CompNode {val = 4, ident = CNId {uid = 7, 
zone = 0}, deps = []}] :: Data.Vector.Vector),(Ref {name = "phi'", lenRef = 2},fromList [CompNode 
{val = -1, ident = CNId {uid = 0, zone = 0}, deps = []},CompNode {val = -1, ident = CNId {uid = 1, 
zone = 0}, deps = []}] :: Data.Vector.Vector),(Ref {name = "psi", lenRef = 2},fromList [CompNode 
{val = -1, ident = CNId {uid = 8, zone = 0}, deps = [CompNode {val = 1, ident = CNId {uid = 4, zone
 = 0}, deps = []},CompNode {val = 2, ident = CNId {uid = 5, zone = 0}, deps = []}]},CompNode {val = 
-1, ident = CNId {uid = 3, zone = 0}, deps = []}] :: Data.Vector.Vector)]

edit

okay, I forgot "print" is more accurately called "show" in haskell... there is a "pretty-show" package. however, it seems to just call show, parse the string, and try to output it in a nice way. i really want something that exposes a new class structure, e.g. class PrettyShow a where prettyShow :: a -> String.

edit 2

pretty-show isn't good enough for my situation; its output is hardly different. I'm writing something with a monad that tracks indentation; if the code evolves into something good enough maybe I'll post it on hackage. Further, I want to write PrettyShow instances for my custom classes just like one can currently write show instances.

1 Answers
Related