[Haskell-cafe] Prettier pretty-printing of data types?

Vincent Hanquez tab at snarc.org
Wed Mar 14 00:08:44 CET 2012


On 03/13/2012 10:33 PM, Johan Tibell wrote:
> value = Bin 1 (Bin 2 Leaf Leaf) (Bin 3 Leaf Leaf)

I'm usually using the following snippet which is a tweak of the gshow function 
from syb.
However everything need to be a member of Data/Typeable, and also list are not 
particularly well handled with this.

gshowHier :: Data a => Int -> a -> String
gshowHier il a = intercalate "\n" (constr : gmapQ (gshowHier (il+2)) a)
      where constr = replicate il ' ' ++ (showConstr $ toConstr a)

-- 
Vincent



More information about the Haskell-Cafe mailing list