In the second half of this course, you will work on a project, which will replace regular homework assignments.
The topic for your project must be discussed and approved before you start working on it.
All projects are individual.
Github repo: You will have to create a Github repository for your project, so your progress can be tracked. Update the repository regularly, at least twice a week. If your repository remains dormant until the last few days, when you suddenly upload everything, you may get a low grade for the project.
On borrowing code: If you use someone else’s code, it must be clearly stated in the project README, what code is yours, and what code is borrowed. Try to keep borrowed code in separate modules (separate files) from your own code to make distinction clear.
Functional style: Your implementation should use only functional aspects of the language (modules List, Map, Set, and String should be your main data structure, together with variant types, tuples, and immutable records). You still can use libraries that work in the imperative fashion with hidden mutable state, however your own code should stay functional or mostly functional.
Some possible specific topics (if you don’t have any particular idea in mind):
tree
or grep
. Should implement command-line flags and options. Use modules Sys and Unix.If you want to use a library, library calls shouldn’t make the majority of your code. The goal is to develop functional programming skill, not to learn a specific library.
OCaml libraries are usually high quality, but documentation may be lacking. If you choose to use a library, make sure:
It is also highly recommended to use only the libraries that can be installed with opam package manager (or if they are single-file libraries that can be simply added to your code base). Opam is the de facto standard now, so a library not supporting it is likely to be out-of-date, not maintained, or hard to use.
Module interface files (.mli) in OCaml are in some sense similar to header files (.h) in C and C++. They don’t have to included in (.ml) files, but they contain the interface of the modules, that is, its type declarations, function signatures, and documentation about the module. Sometimes, they are actually the most definitive source of information about the library functions (if the library does not have web-page).
For example, list.mli for the module List from the standard library contains full documentation about the module. (In fact most of the time, the HTML documentation is generated from .mli files.)
While .mli files are not always very easy to read, they can be very useful, especially if you don’t have any other documentation for the library.
Generally, to compile your program that is using a library, a good strategy is to consult the examples provided by the library itself.
However, most of the time, the ocamlfind
works. Especially if the library is installed with opam,
then adding the library is only a matter of adding options -package NAME -linkpkg
to the ocamlfind
command (here replace NAME
with the name of the library
you want to use).
For example:
Suppose you want to use library cairo2
, your own code consists of 3 files: file1.ml
, file2.ml
, and file3.ml
,
and you want to compile it into an executable called program
. Then the following command will work:
ocamlfind ocamlopt -package cairo2 -linkpkg -o program file1.ml file2.ml file3.ml
For more information, consult this article.