Zora-1.2.0: Graphing library wrapper + assorted useful functions

Copyright(c) Brett Wines 2014
Safe HaskellNone



A typeclass with default implementation for graphing trees with Haskell GraphViz. It is intended to be extremely straightforward to graph your data type; you only need to define one simple function (example implementation below).



class DAGGraphable g where Source

A typeclass for tree-like algebraic data types that are able to be graphed.


expand :: g -> Maybe (Maybe String, [(Maybe String, g)]) Source

Expands a node into its show_node and children. For example, with the following example data type

data Tree a = Empty | Leaf a | Node a (Tree a) (Tree a)

, you might have the following definition:

expand (Empty) = Nothing
expand (Leaf x) = Just (Just $ show x, [])
expand (Node x l r) = Just (Just $ show x, [(Just "L child", l), (Just "R child", r)])

render :: (Eq g, Show g, DAGGraphable g) => String -> g -> IO () Source

Graphs the given DAGGraphable data type to a PDF file. Output is written to the specified file. This is a convenience function that is the composition of render_dotfile and to_dotfile.

to_dotfile :: forall g. (Eq g, Show g, DAGGraphable g) => g -> String Source

Returns a String to be put into a DOT file for the given DAGGraphable type.

render_dotfile :: String -> String -> IO () Source

Graphs the given string as if it were the contents of a DOT file. Output is written to the specified file. The first parameter is the outfile name, and the second is the contents of the dotfile.