Zora-1.1.6: A library of assorted useful functions and data types and classes.

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

Zora.TreeGraphing

Description

A typeclass with default implementation for graphing trees with Haskell GraphViz.

Synopsis

Documentation

class Zoldable g => Graphable g where Source

A typeclass for algebraic data types that are able to be graphed. For these descriptions, assume the following example data type:

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

See the supporting file dot.hs for an example of how to graph your data type.

Minimal complete definition

value, get_children, is_empty

Methods

value :: g a -> a Source

Gets the value contained in a node. For example,

value (Empty) = error "Empty nodes don't contain values."
value (Leaf x) = x
value (Node x _ _) = x

get_children :: g a -> [g a] Source

Gets the children of the current node. For example,

get_children (Empty) = error "Empty nodes don't have children."
get_children (Leaf _) = []
get_children (Node _ l r) = [l, r]

is_empty :: g a -> Bool Source

Returns whether a node is empty. Sometimes, when declaring algebraic data types, it is desirable to have an Empty value constructor. If your data type does not have an Empty value constructor, just always return False.

is_empty (Empty) = True
is_empty _ = False

graph :: forall a. (Show a, Ord a) => g a -> Graph Source

Returns a Graph for the given Graphable type. You shouldn't need to override this implementation.