Copyright | (c) Brett Wines 2014 |
---|---|
License | BSD-style |
Maintainer | bgwines@cs.stanford.edu |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
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
- render :: (Eq g, Show g, DAGGraphable g) => String -> g -> IO ()
- to_dotfile :: forall g. (Eq g, Show g, DAGGraphable g) => g -> String
- render_dotfile :: String -> String -> IO ()
Documentation
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, [("L child", l), ("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.