OCaml is a functional programming language in the ML family. The purpose of this assignment is to set you up with a working OCaml environment (either on your own machine or in one of the labs in Stocker) and to introduce the fundamentals of programming in OCaml.
In general, functional programming languages like OCaml are characterized by their support for
Then, download the CS4100 VM (about 2.5Gb).
(UPDATE 1/18/16: At least one student had problems with the VM above. If you fall into this category, you may have better luck with the Xfce version of the CS4100 VM.)
Now fire up VirtualBox and import the VM by doing "File->Import Appliance". The OS should log in automatically. If you are ever prompted for username or password, use "cs4100" (username) and "cs4100" (password).
Once you've completed the steps above, make sure everything works by jumping to Making Sure Everything Works below.
The easiest way to install OCaml on your own machine is to first install OPAM, the OCaml package manager, and then use OPAM to "switch" to the right version of OCaml. Install OPAM by following the directions here: http://opam.ocaml.org/doc/Install.html.
If you're running Windows, follow the instructions here: http://protz.github.io/ocaml-installer/.
Open a terminal and do
opam initIf you're prompted ("Do you want OPAM to modify ~/.profile..."), type "y" and then hit enter.
Now type
eval `opam config env`
Then do
opam switch 4.02.1and follow the prompts to switch to OCaml version 4.02.1
We'll be using a number of libraries to develop the compiler later on in this course. To install these, do:
opam install ocamlbuild
opam install ocamlfind
opam install batteries
opam install menhirIf you're prompted, just hit "Y" then enter or just enter.
To test that all this worked, follow the insructions in Making Sure Everything Works below.
After logging in to one of the Solaris machines in either 107 or 307, open a terminal and type
opam initNow wait...and keep waiting for quite a while. For some reason related to how the networked file system is set up in the labs, this command takes forever!
At the prompt ("Do you want OPAM to modify ~/.profile..."), type "y" and then hit enter.
Now type
eval `opam config env`After you've initialized and configured OPAM, you need to install Batteries, an enhanced standard library for OCaml. To do so, type
opam install batteriesHit "Y" if prompted. The final library you'll need (for assignments 3 and beyond) is Menhir, a parser generator for OCaml. To install it, type
opam install menhir
To test that all this worked, follow the insructions in Making Sure Everything Works below.
$ ocamlfind batteries/ocamlIf everything worked, you'll be greeted with a screen that looks like:
OCaml version 4.02.1 _____________________________ [| + | | Batteries 2.4 - | |_____|_|____________________| _____________________________ | - Type '#help;;' | | + |] |______________________|_|___| #This is the OCaml toplevel — for interactively executing OCaml code — loaded with the OCaml Batteries Included standard library. At the prompt, try typing something like:
# 1+1;;You should be greeted with a response like:
- : int = 2To exit the toplevel, type Ctl^D.
$ ocamlc.opt intro.ml $ ./a.out