simple data accessors: treeRoot, treeSubtrees; _ “who cares” variable
size: mapping a function over a list
height: max (in BinaryTree height) took two Ords; maximum takes a list of Ords
traversal functions: we can generalize preorder and postorder from binary trees, but how to generalize inorder is unclear (what would it mean?).
concat, map, and concatMap functions on lists
Test tree:
Figure 13. Sketch of test general tree t1
(skip) GeneralTreeFCNS.hs is an implementation of general trees using the first child next sibling representation. It seems more trouble than it’s worth!
(optional) XmlTree2.hs using a full-strength XML package (“xml” from Hackage, the module is Text.XML.Light), shows that real XML processing is a bit more complex due to namespaces and qualified names, node types other than element and text, etc.
A single pattern match won’t reliably suffice, because there are text nodes containing as little as just a \n in the elements’ contents, in addition to the expected sub-elements.
elt@pattern makes elt a variable; its value is whatever matches pattern
elt {field=value, ...} creates a modified copy of elt (so that we don’t have to explicitly give the value of each field).
Encapsulation and information hiding: exports only the type constructor, not data constructor, of TreeSet, thereby hiding its internal structure.
instance declaration instead of automatically derived Show instance further supports information hiding
Possible exercises: add true set operations, including intersection, union, difference, subset (i.e., is A a subset of B?), equality (instance for Eq with a definition of ==; sets A and B are equal if each is a subset of the other).