Assignment 2: List module, primes, and the Towers game.
This assignment is split into three separate files, each unrelated to the other.
src/reimplementation.ml
: you write new solutions to some problems from Assignment 1, but you can only use theList
module and cannot use explicit recursion (i.e., nolet rec
).src/primes.ml
: you write a few functions around prime numbers.src/towers.ml
: you verify that the solution to a Towers game is correct.
File structure and requirements
- Use this zip file as the starting point for your assignment. Download and unzip it.
- Your code will go in three files, each of which contains a full description of the requirements for that file:
src/reimplementation.ml
src/primes.ml
src/towers.ml
- Thoroughly read the instructions in each of these files and write your code to follow the instructions.
- You must add five non-redundant
assert_equal
statements to the tests intest/tests.ml
.- Note there are other provided tests in the following files:
tests/reimplementation_tests.ml
tests/primes_tests.ml
tests/towers_tests.ml
- Your new
assert_equal
statements must be complementary to all tests in these files. Your tests can be on any part of this assignment (e.g. on primes, towers, etc.).
- Note there are other provided tests in the following files:
- There are corresponding
.mli
files that state which functions you must have in your submission. You will not submit these files, so do not edit them. If you edit them, then Gradescope may fail to run your code. Note that for this assignment we also list all funtions you need to define in the.ml
files so you can largely ignore them now; it is more of a warm-up to how real OCaml development works. - The
dune
files are set up for you. They allow you to rundune build
anddune test
from the top level directoryassignment2/
Resources to help you
Here is a reminder of some resources at your disposal.
- Consult the Basic OCaml lecture notes, and if you want to re-watch any lecture they are on Panopto as per the link pinned on Courselore.
- Real World OCaml Chapter 1 is another tutorial introdution in a somewhat different order than we are doing.
- If you are looking for how some standard library function is expressed in OCaml, like not equal, etc, consult the Caml Stdlib which are the predefined functions available in OCaml.
- Note that
Core
overrides some of these including the comparison operations which only work onint
s. To perform=
,<
or the like on e.g. floats you need to writeFloat.(=) 3.2 4.7
for example to check for equality on3.2
and4.7
, and similarly for<
etc. To see what is actually loaded look at the Core documentation. - Use
Core
’sList
module functions where possible; those functions are generally described under theCore
list docs. - You are allowed to work with other people on the assignment; you just need to list the names of people you worked with. However, remember that you should submit your own write up of the answers. Copying of solutions is not allowed. For the full collaboration policy see here.
- Come to office hours to get help from Prof and CAs. Office hours are posted on Courselore.
- Use Courselore for online help and question clarification.
Coding Methods
- There are two ways to test your code.
- Run it in the top loop with
utop
. To load all of your functions into the top loop in one go you can use the OCaml top-loop directive#use "src/submission.ml";;
which is the same as copy/pasting that file into the top loop as input. Make sure you startedutop
from theassignment2/
directory for this to work. Alternatively, you can use thedune utop
command to load your code upon starting. - Run
dune test
from the main directory (assignment2/
). All of these tests should pass because we will run it when you submit your code. Remember to add five of your own tests.
- Run it in the top loop with
- Note that all
dune
commands should be run directly from theassignment2/
directory ONLY.dune
automatically will also run the build files in any sub-directories by default, so this will run thedune
files insrc/
andtest/
if required. Also note thatdune test
will implicitly invokedune build
if your code is not compiled yet.
Submission and Grading
- Follow the same procedure as Assignment 1 to upload to Gradescope.
- Run
dune build
and submit the zip file at_build/default/assignment2.zip
.
- Run
- The autograder will run the tests we gave you and any additional tests you add.
- You will be graded on adding five additional tests.
- The autograder will also run our own tests that you might not see (yet). Ensure your own tests are complete to pass all of our hidden tests.
- We will hand-inspect your code, but we won’t enforce style guidelines until the next assignment.
- You can submit the HW as many times as you want up to the deadline. Any submissions after the deadline will fall under the late submission policy.
- Please submit your draft HW at least once well ahead of the deadline, so you do not find some problem right at the deadline.