CS 331 Spring 2013  >  Assignment 4

CS 331 Spring 2013
Assignment 4

Assignment 4 is due at 5 p.m. Sunday, March 3. It is worth 20 points.


E-mail answers to the exercises below to ggchappell@alaska.edu, using the subject “PA4”.

Exercises (20 pts total)

Exercise A — Running a Haskell Program


In this exercise you will make sure you can execute Haskell code.


Run the program check_haskell.hs (on the class web page). Tell me what it does.

If you use the AOT compiler (GHC), then compile the program and run the resulting executable. If you use an interactive environment (GHCi or Hugs), then load the source file and run function main.

Exercise B — Writing Haskell Code


In this exercise, you will write some simple Haskell functions, including one infix operator.


Write a Haskell module PA4, contained in the file PA4.hs (note the capitalization in the filename!). Module PA4 should include the following five public functions/variables/operators: filterAB, collatzCounts, findList, ##, sumEvenOdd.

Code Structure

Test Program

A test program is available: pa4_test.hs. This will test whether your package works properly. (It will not test whether sumEvenOdd is implemented as required.)

If you are using GHCi (or Hugs), then put your file and the test program in the same directory, and do

> :l pa4_test
> main

(Note that “> ” represents the GHCi prompt, and is not to be typed.)

Do not turn in pa4_test.hs.

CS 331 Spring 2013: Assignment 4 / Updated: 26 Feb 2013 / Glenn G. Chappell / ggchappell@alaska.edu