Assignment 1: OCaml Introduction
In this assignment, you are to write several small programs in OCaml.
The file structure
- Use this zip file as the starting point for your assignment. Download and unzip it.
- We are starting right off with the standard file structure recommended for projects built with the
dunebuild tool, and you will be usingduneto test your program. Please keep this file structure in your coding and submission. - The file
assignment1/src/submission.mlis where you will put your answer code. Currently it hasunimplemented ()for all the functions, which you will replace with your code.- You may add
recto any function you’d like. - You can add any auxiliary functions of your own; put them right before you need to use them.
- You may reorder functions in any way you like.
- You may add
- You may also edit
assignment1/test/tests.mlwhich contains some initial tests. These tests are not complete, and you should add more, but you are not required to. - The file
assignment1/src/submission.mlistates which functions you are required to have in your submission. You will not submit this file; Gradescope has its own copy. Your submission will not run on Gradescope if you have not defined every function described inassignment1/src/submission.mli. - There is a
assignment1/src/duneandassignment1/test/dunefile we set up for you. They allow you to run commandsdune buildanddune testrespectively from the top level directoryassignment1/to build and/or test your code.- Note you want to stay in the top level to run these commands because
duneautomatically builds subdirectories. - Also note that running
dune testtwice in a row will show you no output. It knows that nothing has changed since the previous run, so it skips the tests the second time.
- Note you want to stay in the top level to run these commands because
- There is also an
assignment1/dunefile which just builds a zip of all the files for submission. When you are all done with the homework, perform a finaldune buildto build the zip. See the submission section below for more on this.
Resources to help you
Here is a reminder of some resources at your disposal.
- Consult the Course Coding page for information on installing OCaml and getting a good toolchain setup for development.
- Consult the OCaml Intro 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 introduction in a somewhat different order than we are doing. They use the
Corestandard library overlay, so their library functions may look different than yours. - 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.
- You are 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 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
- Before you even open any files in VSCode, type
dune buildfrom theassignment1/directory. This will set up the editor to recognize the libraries.- If your VSCode editor is not synced across files, run a
dune build, and then open the command palette (Ctrl+Shift+P Win or Cmd+Shift+P Mac) and run theOCaml: Restart Language Servercommand.
- If your VSCode editor is not synced across files, run a
- There are two ways you can test your code in OCaml, (1) you can use the top loop (
utop) to informally run some tests on it, and (2) you can run thedune testscript from directoryassignment1/, which runs all of the small suite of tests in the filetest/tests.mland reports the results.- 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 startedutopfrom theassignment1/directory for this to work. - Alternatively, you can issue the command
dune utop, which builds and startsutopwith your code loaded. Then, typeopen Submission;;inutopto open up the moduleSubmissioncontaining your code so that you can directly use your functions.
- To load all of your functions into the top loop in one go, you can use the OCaml top-loop directive
- It is up to you which way you prefer, but both have their advantages, and we suggest you do some of each. You are required to have the
dune testmode working because we will run those tests when you submit. - Note that all
dunecommands should be run directly from theassignment1/directory ONLY.duneautomatically will also run the build files in any sub-directories by default, so this will run thedunefiles insrc/andtest/if required. Also note thatdune testwill implicitly invokedune buildif your code is not compiled since the last edit.
Submission and Grading
- We will be using Gradescope to submit programming assignments. The Gradescope entry code is posted on Courselore.
- Upload your
assignment1.zipsolutions file that is built bydune, which you will find inassignment1/_build/default/assignment1.zip. - The Autograder will run the tests we gave you; it will also run additional tests that you might not see (yet). On top of the autograder, we will be hand-inspecting your code, but we won’t be enforcing style guidelines yet.
- If you can’t fix the Gradescope error and/or it makes no sense, post to Courselore or see someone in office hours.
- You can submit the assignment 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 assignment at least once well ahead of the deadline so that you do not find some problem right at the deadline. We will only look at and grade the most recent submission.