CMPT 383

Summer 2009

 

Programming Assignment 1

Due: Friday, May 29, at 5:00 PM. Submit your solution using the CSIL Submit Server.

The Haskell Ratio Library can be imported into a Haskell script by including the statement

import Ratio

at the top of the script. This library supports type Rational. A value of type Rational can be produced by applying the binary operator % to two Integers. For example, the expression 4 % 6 will produce the rational number that is the result of dividing 4 by 6.

Ratio

Using Haskell, produce an infinite list of all of the rational numbers between zero and one. Each value should occur exactly once in the list. You are free to produce the rational numbers in any order.

You should print the following results:

  1. The list of the first 20 rational numbers in your list. These values will depend on the order you choose for the rationals.
  2. The number of rational numbers the exist in the list of all rational numbers before the value 4%17

  1. Carefully read the subsection of the course web page on Format of Submitted Work.
  2. Notice that you are responsible for choosing appropriate test data. (However, this does not apply to this first assignment.)
  3. Carefully read the subsection of the course web page on Getting Help from Others.
  4. Look at the final sentence of the course web page.
  5. Do your assignment.

In this and other programming assignments, at least half your grade will depend on the clarity, simplicity and organization of your code, including the documentation (usually in the form of comments).