OCaml Warmup
Description
Complete the function definitions in the warmup.ml file. In your code, you
may only use library functions found in the Stdlib
module. (This
means you may not use the List module!) You may not use any
imperative structures of OCaml such as references.
Instructions
To start the assignment, download the project1-handout.zip file from
D2L. Then unzip the file to your development environment. If you wish
to develop on the CSIT Linux server, then you need to add:
/home/kutztown.edu/schwesin/.opam/default/bin
to your PATH environment variable. One way to do this is to add the following
line to your ~/.bashrc file and then either source the file or log out and
log back in:
export PATH=/home/kutztown.edu/schwesin/.opam/default/bin:${PATH}
To execute the test cases, run the following command:
dune runtest -f
To list the public test cases, run the command:
dune exec test/public.exe -- -list-test
To run a specific public test case, run the command:
dune exec test/public.exe -- -only-test <test case name>
To load all the function definitions into the OCaml top-level run the following command within the top-level (REPL):
#use_output "dune ocaml top";;
The following are the relevant files for your code:
- OCaml Files
- src/warmup.ml: Write your code in this file.
- src/warmup.mli: This file is used to describe the signature of all the functions in the module. Do not modify this file.
- test/student.ml: Write at least one additional test case in this file.
To submit your assignment, create a zip file of a DIRECTORY named
project1-handin containing ONLY the warmup.ml file. Then submit that
file to the appropriate folder on D2L.
Notes on OCaml
OCaml is a lot different than languages you are used to working with in other courses. Here are some points to consider:
Unlike most other languages,
=in OCaml is the operator for structural equality whereas==is the operator for physical equality. All functions in this project (and in this course, unless ever specified otherwise) are concerned with structural equality.The binary subtraction operator (
-) also doubles as the unary minus operator forints andfloats in OCaml. As a result, the parser has trouble identifying the difference between subtraction and a negative number. It always safe to surround unary minus in parentheses. For example,some_function 5 (-10)works, wheresome_function 5 -10will give an error.Recursive functions in OCaml require the use of the
reckeyword. Thereckeyword is not included for certain functions inwarmup.mlto show that the function can be written without recursion. Addingrecto a non-recursive function usually has no effect (unless there is some sort of shadowing going on.)
Here are some additional notes about this particular project:
You can always add a helper function for any of the functions that you need to implement, and the helper function can also be recursive.
You may move around the function definitions. In OCaml, in order to use one function inside of another, you need to define the function before it is called. For example, if you think that a function from Part 2 can be used to help you implement a function in Part 1, you can move your implementation of the function from the Part 2 section to before the function in Part 1. As long as you still pass the tests and you have not created a syntax error, you are fine.
Pay special notice to a function’s type. Often times, you can lose sight of what you are attempting if you don not keep the types of the arguments and the type of what you are trying to return in mind.
You may rename arguments however you would like, but do not modify function’s name. This will cause the tests to fail.
Turning in the Assignment
To submit your assignment, create a zip file of a DIRECTORY named
project1-handin containing ONLY the these files:
warmup.mlstudent.ml
Then submit that file to the appropriate folder on D2L.
Grading Criteria
Grading (out of 60 points):
- 45 points — correctness
- 3 points per function implemented
- 15 points — test cases
- 1 point per function implemented
Academic Integrity
Please carefully read the Computer Science Academic Integrity Policy. Any evidence of impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be considered academic dishonesty. Lack of knowledge of the policies will not be considered as a defense for violating them.