One option is to use the diagrams library, which has many backends. The diagrams-contrib package includes helper functions for rendering trees . Therefore, perhaps you can convert the parse tree to a pink tree from Data.Tree and make it that way.
The following example uses an SVG server:
module Treeish where -- This example requires the containers, -- diagrams-core, diagrams-lib, diagrams-contrib and diagrams-svg packages import Data.Tree import Diagrams.Prelude import Diagrams.TwoD.Layout.Tree (renderTree,symmLayout',_slHSep,_slVSep) import Diagrams.Backend.SVG (SVG) import Diagrams.Backend.SVG.CmdLine (defaultMain) exampleTree :: Tree String exampleTree = Node "A" [Node "B" [], Node "C" []] renderNodeTree :: Tree String -> QDiagram SVG V2 Double Any renderNodeTree nodeTree = renderTree (\a -> letter a `atop` square 1.03 # fc white) (~~) (symmLayout' (with{ _slHSep = 3, _slVSep = 2}) nodeTree) where letter a = text a # font "monospace" # fontSize (local 0.47) main :: IO () main = defaultMain (renderNodeTree exampleTree)
renderTree is a function that, when renderTree a function that creates a diagram for a node tree, and a function that creates a line between two given points, returns a function that creates a diagram from a tree that was annotated with node positions.
Position annotations are added using the symmLayout' function.
with is simply a synonym for default from Data.Default .
(~~) creates a line between two points.
When the program starts from the command line (with something like runhaskell Treeish -o foo.svg -w 300 ), it will generate an SVG file that can be viewed in a browser:

Here and here are two parts of a recent tutorial on diagrams .
source share