Assignment 1: OCaml basics

You are to write several small programs in OCaml.

  • Use the this zip file as the starting point for your assignment. Download and unzip it, all will be in folder assignment1.
  • We are using the standard file structure recommended for OCaml projects built with the dune build tool (the OCaml equivalent of make). Please keep this file structure.
  • The file assignment1/src/assignment.ml is where you will put your answer code. Currently it has unimplemented () for all the functions, replace that with your code.
  • The only other file you might want to edit is assignment1/tests/tests.ml which contains some initial tests; you are welcome to add your own tests.
  • The terminal command dune build run from the top level assignment1/ directory will build (compile) all your functions in the assignment.ml file.
  • The terminal command dune test also run from assignment1/ will build the code and run all the tests in the above test.ml file. It will report on each test whether it succeeded or failed.
  • To play with your code in utop, you could copy/paste your functions directly into the top loop, but a perhaps easier way is to type terminal command dune utop, again from the assignment1/ directory. This will compile all your functions and load them into utop. They will all be part of a module Assignment since the file was called assignment.ml; so, next type open Assignment;; into utop so the functions will be directly available – you will then be able to type e.g. nth_exn 1 [1;2;3;4];; to informally test your code.
  • When you are all done the homework, from directory assignment1 run the command dune build one last time which will build _build/src/submission.zip – that is the zip file you should upload to Gradescope.

Resources to help you

Here is a reminder of some resources at your disposal.

  • Consult the code examples run in class.
  • Consult the Course OCaml page for information on installing OCaml and getting a good toolchain setup for development
  • You are required to use OCaml version 5.1.1 and we strongly recommend using Visual Studio Code for editing. Again see the OCaml page for how to get an editor working.
  • For more OCaml examples etc, read and copy/paste the code defined in the OCaml.org tutorials (mainly “the Basics” for this assignment).
  • If you are looking for how some standard function is expressed in OCaml, like not equal, etc, consult the Caml Stdlib which contains the predefined functions available in OCaml.
  • Note for this first assignment you can only use things in this standard library; you cannot use list library functions such as List.hd or List.nth (you can code your own versions, of course).
  • You are strongly encouraged 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 the office hours, to get help from Prof, TAs, and your peers. They are pinned on Courselore.
  • Use Courselore for additional help and question clarification. Make sure to also watch the posts there for question clarifications.

Submission and Grading

  • We will be using Gradescope to submit programming assignments. The Gradescope entry code is posted on Courselore.
  • The Autograder will not be up immediately but we will announce when it is up.
  • When asked to, upload your _build/default/src/submission.zip zip file which should be generated by dune build.
  • You will see some test results when you run the autograder; we also may use some hidden tests which you will not be able to see the results on. More tests may also be added after the submission deadine. Your goal is to meet the specification of the assignment, not just to see a happy autograder on your submission.
  • After all HWs are turned in we will show you the hidden tests and how you did on them, but not until then.
  • 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 HW early and often to Gradescope, don’t just wait until 10 minutes before the deadline, and report any problems/bugs to the instructors on Courselore.
  • Any CA can look at your submission and see the details of the processing by Gradescope, so if you don’t understand what the problem is just see a CA or post to Staff on Courselore.
  • Please don’t try to “game” the auto-grading system or hack it. Your grade will be 0 on the assignment if gaming is detected, and any hacking will be considered a serious ethics violation.