Programming assignments how-to

In the lecture we looked at how to write and run little programs in the interpreter. For submission you will need to write the assignment in a separate file. Here is how.

Lets suppose that you want to submit a function called max3 : int * int * int -> int which calculates the maximum of three numbers. First you experiment in the interpreter until you are happy with your implementation. Suppose that this is the script of my attempts:

Objective Caml version 3.11.0

# let max3 (a, b, c) = max (a (max b c));;
val max3 : ('a -> 'b) * 'a * 'a -> 'b -> 'b = <fun>
# max;;
- : 'a -> 'a -> 'a = <fun>
# let max2 (b, c) = max b c;;
val max2 : 'a * 'a -> 'a = <fun>
# let max3 (ax, b, c) = max (a (max b c));;
val max3 : ('a -> 'b) * 'a * 'a -> 'b -> 'b = <fun>
# let max3 (x, y, z) = max x (max y z);;
val max3 : 'a * 'a * 'a -> 'a = <fun>
# max3 (1, 2, 3);;
- : int = 3
# max3 (2, 4, 1);;
- : int = 4

This script includes some erroneous attempts, the final correct definition and some testing. This is not what you are supposed to submit. You need to submit just the definition of the function. Note that if this definition uses other definitions they also need to be included, and so on. 

In this case, you need to create a new file and write in it only the definition,

let max3 (x, y, z) = max x (max y z)

Note that the terminator ;; needs not to be included!

As a final check before you submit do the following steps:
  1. restart the OCaml interpreter. This will ensure that any old definitions are forgotten and the system returns to its default state.
  2. paste the function definition in the interpreter, so it should look like this:

    Objective Caml version 3.11.0

    let max3 (x, y, z) = max x (max y z);;
    val max3 : 'a * 'a * 'a -> 'a = <fun>

  3. now try again some of the tests and make sure they are OK:
    # max3 (1, 2, 3);;
    - : int = 3
    # max3 (2, 4, 1);;
    - : int = 4
Now you can submit your file!

It is important to go through this little test in order to ensure that you submit only the relevant definitions for assessment. 
Comments