Recursive functions. GitHub issues.
You may need to refer to the Pervasives module documentation occasionally. All the functions there are available in OCAML by default. You are NOT allowed to use everything that’s there unless we have talked about it or unless the assignment question asks you to look it up.
In this assignment you are asked to implement 9 functions. Each function is worth two points, and the assignment has two extra points for “style”, for a total of 20 points.
The assignment expects you to use GitHub and Git to keep track of your work. You have already set up GitHub on your first assignment. What we need to do now is “update” your GitHub with the new information. This is a somewhat delicate process, as your “branch” has deviated from the instructor’s “branch”, and we need to realign them.
git remote add instr https://github.com/skiadas/ProgLangAssignments.git
git remote -v
and you should see a list of 4 items, two called “instr” and two called “origin”.git fetch instr
git merge master instr/master
. This may give you a editor window to edit a commit message. You don’t need to edit it, just “save” (writeOut) and exit. (This is probably not your prefered editor. See this page for how to set up your favorite editor for use in these merge situations. I would recommend setting it to SublimeText).#1
. You can use those numbers to refer to issues.Now you should go to the assignments file, read through the functions and for now implement “stubs” for them. So for each function you would write something like:
let f (x : int) = (x, 1)
where of course you need to make sure these are the “right things” type-wise. The point of this part is to get the function signature right. So the value you use on the right may be completely wrong, for now, but we just want it there to correctly identify the types of functions.#use "assignment2sub.ml;;"
to make sure the signature is right, and if it is then check off the corresponding checkbox in the task list we created in GitHub for this issue.git add .
This “prepares” your changes for committing. You can also do git add assignment2sub.ml
to add just the one file (otherwise it picks up all changes in that directory).git status
This should show you the one file ready for commit.git commit -m "Implement hw2 stubs. Close #1"
This creates a commit, and the last line should be typed exactly that way (with the number reflecting which issue you want to close).git push origin master
This should upload your changes to GitHub, and also automatically close that issue.assignment2sub.ml
This is the main submission file. It is where you will add your code for the various functions that you need to write. There are comments in that file to show you where to add your function definitions, and to tell you what your functions should do.assignment2tests.ml
This is a file with a small number of tests, and you should add plenty tests your own. “Tests” are arranged as lines let ... = e
where e
is a an expression that is meant to evaluate to a boolean indicating if the tests succeeded or not.To “run” your tests, start an OCAML session in the terminal via utop
, do:
#use "assignment2sub.ml";;
#use "assignment2tests.ml";;
You should be able to use auto-completion.
#use
should print for you the type signatures for all the functions you had to write. Make sure this matches the signatures described in the code file.#use
should print a bunch of true
values out, for all the existing tests along with all the tests you added.