CSci 555: Functional Programming
Spring Semester 2000

Assignment #1
Due Tuesday, 1 February, 8:00 A.M.


This is an individual assignment, which you must complete in accordance with the instructions given in the Professional Conduct and Assignments sections of the Syllabus .

Write the Haskell functions described in the following exercises. You should put all the definitions in the same script (i.e., source code) file, but please add comments that enable your instructor to determine which functions comprise your work on each exercise.

Please format and document your source code appropriately. Also test your programs thoroughly.

  1. Suppose we have to raise 2 to a power n.

    If n is even, then 2^n = 2^(2*m) = (2^m)^2 for some m.

    If n is odd, then 2^n = 2^(2*m + 1) = ((2^m)^2)*2 for some m.

    Using these ideas, give a recursive definition of a Haskell function twopow n that computes 2 ^ n for any natural number n. Your function cannot use the exponentiation operator ^ or any exponentiation function in the standard prelude. The number of calls your program makes to twopow during execution should be proportional to the logarithm of n (base 2).

  2. Write a Haskell function that takes a list of floating point numbers and computes the mean (i.e., average) value for list. If you can, do this with a function that only needs to make one pass through the list.

  3. Write a Haskell function that returns the middle element of an odd-length list.

  4. Write the Haskell functions natToBase and baseToNat described in exercise 7 on page 49 of the Notes on Functional Programming with Gofer.

When this assignment is complete, submit:

Be sure that all items submitted are clearly labeled with your name and the assignment number.


UP to CSCI 555 assignments document?


Copyright © 2000, H. Conrad Cunningham
Last modified: Mon Apr 3 21:24:14 CDT 2000