Homework 5
Object-Oriented and Functional Programming

Due on Tuesday May 3 before midnight


This homework must be done individually. No copying is permitted.

  1. (40 points) Problem 10.31 (a) in the textbook (p466). Note: do not do the part (b) of Problem 10.31.

  2. (60 points) Consider the following Haskell definition of XML data:
    data XML = Element String [XML]
             | Text String
    For example, the XML data <q><s>y</s>d<s>z</s></q> is constructed using
    Element "q" [ Element "s" [Text "y"], 
                  Text "d",
                  Element "s" [Text "z"] ]
    Write a recursive Haskell function count of type XML->Int that counts the total number of nodes in XML data (Element and Text nodes). For example, it must return 6 for the above XML data.

What to Submit

Use the form below to submit your homework. We do not accept email or hardcopy submissions. Acceptable file formats for your submitted file are: plain text, Microsoft Word document (.doc), PDF (.pdf), and postscript (.ps). Don't forget to put your name and student ID on your homework. You may submit your file as many times as you like, but only the most recently submitted file will be retained and evaluated.

Submit Homework #5:

Last modified: 26/04/11 by Leonidas Fegaras