Zora-1.2.0: Graphing library wrapper + assorted useful functions

Copyright(c) Brett Wines 2014
LicenseBSD-style
Maintainerbgwines@cs.stanford.edu
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Zora.Graphing.DAGGraphing

Description

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).

Synopsis

Documentation

class DAGGraphable g where Source

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

Methods

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.