CSci 555: Functional Programming
Spring Semester 2001

Assignment #3
Due Friday, 2 March 2001


  1. Define functions to give the sum of the squares of the negative values in a list of integers (type Int).
    1. Give a backward recursive definition.
    2. Give a definition that uses a tail recursive auxiliary function.
    3. Give a definition that uses standard prelude functions such as map, filter, foldr, and foldl.
    4. Give a definition that uses a list comprehension.

  2. Define a function total
        total :: (Int -> Int) -> (Int -> Int)
    
    so that total f n gives
        f 0 + f 1 + f 2 + ... + f n
    

  3. Define a function
        filterFirst :: (a -> Bool) -> [a] -> [a}
    
    so that filterFirst p xs removes the first element of xs that does not have the property p.

  4. Define a function
        filterLast :: (a -> Bool) -> [a] -> [a}
    
    so that filterLast p xs removes the last occurrence of element of xs that does not have the property p. How could you define it using filterFirst?

  5. Do exercise #3 on page 75 of the Notes.

  6. Do exercise #4 on page 75 of the Notes.

Please format and document your program source code appropriately. (All of the above functions should be defined in the same file.)

Test your programs appropriately and thoroughly.

When this assignment is complete, submit a paper listing of your program source code and the screen outputs from executing the program. Be sure that all items submitted are clearly labeled with your name and the assignment number.

Also submit your program source code using MESH at URL http://www.cherry.cs.olemiss.edu/mesh/. Your username and password for that system was given to you earlier.


UP to CSCI 555 assignments document?


Copyright © 2001, H. Conrad Cunningham
Last modified: Tue Apr 17 15:30:34 2001