[Haskell-cafe] Pretty printing a tree

Andrew Wagner wagner.andrew at gmail.com
Thu May 14 15:00:08 EDT 2009


Perhaps drawTree on
http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Tree.html
2009/5/14 José Romildo Malaquias <j.romildo at gmail.com>

> Hello.
>
> I would like to pretty print a tree in a way that its structure is
> easily perceived.
>
> For instance, consider the declarations:
>
>   data Node a = Node a [Node a]
>
>   type Tree a = [ Node a ]
>
>   t = [ Node "a" [ Node "b" []
>                  , Node "c" [ Node "c1" []
>                             , Node "c2" [] ]
>                  , Node "d" [ Node "d1" [ Node "d1a" [] ]
>                             , Node "d2" [] ] ] ]
>
> Then the resulting of pretty printing the given tree would be something
> like the following:
>
>       a
>       |
> +-------------+
> |    |        |
> b    c        d
>     |        |
>   +---+    +---+
>   |   |    |   |
>   c1  c2   d1  d2
>            |
>           d1a
>
> There is the module Text.PrettyPrint.HughesPJ, but it lacks examples on
> how to use the pretty print combinators, and it is not well docomented.
>
> I would like to see solutions for this problem, or clues on how to solve
> it.
>
> Regards,
>
> José Romildo
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090514/1e28df6f/attachment.html


More information about the Haskell-Cafe mailing list