- Install opam (these instructions assume opam version 2+). If you are using Windows, it is highly recommended that you use Windows Subsystem for Linux (WSL). More detailed instructions on how to install opam on WSL can be found here
- Create a new switch (you can replace "homework" with any switch name you'd like):
opam init
opam switch create homework 4.09.0
eval $(opam env)
- Install dependencies:
opam install core dune merlin ounit2
-
Build with
make
. This will create symlinks to four binaries. They are:while
: a While interpreterw3a
: a While3addr interpretercompile
: a While to While3addr compileranalyze
: analyzes a While3addr file (using your analysis) and outputs the results All of these binaries take input on stdin and output on stdout (i.e., you can run a While program by running./while < program.while
, not by passing a file as input).
-
Test with
make test
. This will run any test cases placed intest/test_analysis.ml
. There are a few test cases already provided in thetest_analysis.ml
file to help you get started with testing your code, and we highly suggest that you add more!
Handin only src/analysis/df.ml
to Gradescope to run your code against a set of held out test cases.
- You might be interested in reading Adam Chlipala's overview of the philosophic differences between OCaml and SML: http://adam.chlipala.net/mlcomp/
- This page has a nice side-by-side comparison of the syntax of SML and OCaml: https://people.mpi-sws.org/~rossberg/sml-vs-ocaml.html
- We are using the Core library maintained by Jane Street as it is more feature-rich than the OCaml standard library. The API documentation on that page should be useful.
- If you're using Vim or Emacs, Merlin is a very useful tool that adds features like autocompletion and function signature lookup. The Merlin GitHub page will help you get set up.
- If you're using Emacs, Tuareg mode is a good editing mode.
- OCaml is a compiled or interpreted language, so it can be run in a
REPL. You
can use the standard OCaml REPL, but we recommend
UTop, which can be installed with
opam install utop
. - The official OCaml site has a lot of resources for learning OCaml.
- Real World OCaml is a great book for learning OCaml and is available free online.