Extend the List module developed in the notes on Functional Data
Structures (source
code) to include the following Scala functions.
maxList, which takes a list of values and returns
its maximum value. orList, which takes a list of Booleans and returns
the logical or of the values (i.e., true if any
are true, otherwise false). andList, which takes a list of Booleans and returns
the logical and of the values (i.e., true if all
are true, otherwise false). remdups1, which is like remdups
except it is implemented using either foldRight or
foldLeft. total, which takes a nonnegative integer
n and a function f and returns
f(0) + f(1) + ... f(n). flip, which takes a function of polymorphic type
(A,B) => C and returns a function of type
(B,A) => C such that f(x,y) =
flip(f)(y,x) for all x and
y. A general tree is a data structure in which each node has
zero or more subtrees. Given the following definitions for a Scala
data type GTree
sealed trait GTree[+A]
case class Leaf[+A](value: A) extends GTree[A]
case class Gnode[+A](gnode: List[GTree[A]]) extends GTree[A]
define the following functions (using functions from the extended
List module as needed).
numLeavesGT, which counts the number of leaves in
a GTree heightGT, which computes the height of a
GTree (i.e., the number of levels) sumGT, which sums a GTree of
integers findGT, which finds whether an element occurs in a
GTree mapGT, which maps a function over the elements at
the leaves of a GTree flattenGT, which flattens a GTree to
a List Design appropriate tests for your functions and test them thoroughly.
Document your program appropriately.
Submit the source code and documentation for your program and test driver, any needed instructions on how to run the program, and appropriate test output to Blackboard. Be sure to identify yourself in the materials turned in.
UP to CSci 555 Assignments? /