Tree examples for assignment 5

This page has some examples of trees built using the IBranch and ILeaf constructors specified in assignment 5.

We’ll use this shortcut for a “terminal branch” – one whose left and right children are both empty:



The result of fmap square t1
The result of fmap square t1

The result of flipTree t1
The result of flipTree t1







The result of balancedFromList range
The result of balancedFromList range

The result of balancedFromList (words phrase)
The result of balancedFromList (words phrase)

Generating figures

You don’t necessarily need to look at this section, but I’ll describe what it does in case you’re curious. The function graphviz takes a tree and converts it into a string in a language called GraphViz that can then be fed to a command-line tool to produce images. All the diagrams of trees on this page were produced from this Haskell program and GraphViz.

A compact string representation of trees:

Used in some tests: