CMSC 330, Fall 2009

Organization of Programming Languages

Project 3 - OCaml Warmup

Due 11:59pm Tue, Oct 20th, 2009

Introduction

You will need to implement a few simple functions in OCaml as a warmup project.

Getting Started

Download the following archive file p3.zip and extract its contents.

Along with files used to make direct submissions to the submit server (submit.jar, .submit, submit.rb), you will find the following project files:

The public test files will include your code in warmup.ml, so you can test your OCaml code by typing commands like ocaml public_prod.ml. To see how your code performs on the public test, you can use the test script file goTest.rb to run all public tests locally. Alternatively, you can use the "ocaml myTest.ml" to run your own test cases.

Warmup Exercises

Implement the following functions in OCaml. Do not use any functions in the List or Array modules, i.e., write every function from scratch using just list notation [...], ::, and pattern matching. You should also not use the list concatenation operator @ from Pervasives.

  • Write a function prod l : int list -> int that returns the product of the elements of l. The function prod should return 1 if the list is empty.
  • Write a function add_tail l e : 'a list -> 'a -> 'a list that takes a list l and a single element e and returns a new list where e is appended to the back of l. For example, add_tail [1;2] 3 = [1;2;3].
  • Write a function index l e : 'a list -> 'a -> int that takes a list and a single element and returns the position of the last occurrence of that element in the list (indexed by zero). You should return -1 if the element is not in the list.
  • Write a function unzip l : ('a*'b) list -> ('a list)*('b list) that given a list of pairs, returns a pair of lists with the elements in the same order. For example, unzip [(1, 2); (3, 4)] = ([1; 3], [2;4]).
  • Write a function app_int f m n : (int->'a)->int->int->'a list that returns the list [f m; f (m+1); ...; f n]. It should return the empty list if n < m.

Submission

You can submit your project in two ways:
  • Submit your warmup.ml file directly to the submit server by clicking on the submit link in the column "web submission".

    Next, use the submit dialog to submit your warmup.ml file directly.

    Select your file using the "Browse" button, then press the "Submit project!" button. You do not need to put it in a Jar or Zip file. Some students have mentioned problems with using Internet Explorer, because submissions being extracted in directories (e.g., "C:\My Documents\330\warmup.ml") where the submit server could not find them. The problems went away when switching to the Mozilla Firefox browser.

  • Submit directly by executing a Java program on a computer with Java and network access. Use the submit.jar file from the archive p3.zip, To submit, go to the directory containing your project, then either execute submit.rb or type the following command directly:

    java -jar submit.jar

    You will be asked to enter your class account and password, then all files in the directory (and its subdirectories) will be put in a jar file and submitted to the submit server. If your submission is successful you will see the message:

    Successful submission # received for project 3

Hints and Tips

  • Be sure you have read and understand the project grading policies in the course syllabus. Do this well in advance of the project due date.

    Academic Integrity

    The Campus Senate has adopted a policy asking students to include the following statement on each assignment in every course: "I pledge on my honor that I have not given or received any unauthorized assistance on this assignment." Consequently your program is requested to contain this pledge in a comment near the top.

    Please carefully read the academic honesty section of the course syllabus. Any evidence of impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be submitted to the Student Honor Council, which could result in an XF for the course, or suspension or expulsion from the University. Be sure you understand what you are and what you are not permitted to do in regards to academic integrity when it comes to project assignments. These policies apply to all students, and the Student Honor Council does not consider lack of knowledge of the policies to be a defense for violating them. Full information is found in the course syllabus---please review it at this time.