Docsity

Exercise Solutions for COSC 3015: Summing and Flattening Rose Trees in Haskell - Prof. Jam, Assignments of Computer Science

Toggle sidebar
bg1
HW 14 Prof. Caldwell
Due: 23 October 2008 COSC 3015
Exercise 0.1. Read the section in Bird on Rose trees (pgs 195 - 209)
Exercise 0.2. Write a Haskell program to sum up all of the values in a Rose tree.
The type specification is:
sumRose:: (Num a) => Rose a -> a
You will need to write code to test your function.
Exercise 0.3. Write flatten for Rose trees with the following specification:
1. The head of the resulting list is the root of the tree.
2. All of the values in the left most subtree appear first in the flattened list.
So for example:
flatten (Node 5 [Node 3 [], Node 7 [Node 8 [], Node 9 []], Node 4 []]) =
[5,3,7,8,9,4]
1

Partial preview of the text

Download Exercise Solutions for COSC 3015: Summing and Flattening Rose Trees in Haskell - Prof. Jam and more Assignments Computer Science in PDF only on Docsity!

HW 14 Prof. Caldwell Due: 23 October 2008 COSC 3015

Exercise 0.1. Read the section in Bird on Rose trees (pgs 195 - 209)

Exercise 0.2. Write a Haskell program to sum up all of the values in a Rose tree. The type specification is:

sumRose:: (Num a) => Rose a -> a

You will need to write code to test your function.

Exercise 0.3. Write flatten for Rose trees with the following specification:

  1. The head of the resulting list is the root of the tree.
  2. All of the values in the left most subtree appear first in the flattened list.

So for example:

flatten (Node 5 [Node 3 [], Node 7 [Node 8 [], Node 9 []], Node 4 []]) = [5,3,7,8,9,4]