Compilers

OCaml Warm-Up

Due on Tuesday, January 28th at 11:59 PM. This is an individual lab. You are to complete this lab on your own, although you may discuss the lab concepts with your classmates. Remember the Academic Integrity Policy: do not show your code to anyone outside of the course staff and do not look at anyone else’s code for this lab. If you need help, please post on the course forum forum or contact the instructor. If you have any doubts about what is okay and what is not, it’s much safer to ask than to risk violating the Academic Integrity Policy.

Overview

This lab will serve as an introduction to OCaml. You will write a series of functions and other snippets of code designed to familiarize you with the language. This will also ensure that your environment is prepared so you don’t have trouble in later assignments.

Getting Started

First and foremost, you must set up an environment to allow you to use OCaml. You have three choices here:

  1. You can use OCaml in person on the CS department lab machines. This requires that you have physical access to the lab.
  2. You can use the CS network remotely with your own computer as a front-end. This requires a network connection as you work but is the simpler remote option.
  3. You can use your own computer exclusively without relying on the CS network. This is a bit more work, since you’ll need to install the compiler and other tools yourself. You’ll also need to verify that your compiler assignments work on the lab computers before turning them in, as your system may differ from the CS network systems in some important ways.

Whichever option you pick, you should have not only the ability to compile OCaml programs but also an editor that provides modern development features: syntax highlighting, code inspection, and so on. If you have trouble getting anything to work, make sure to post on the course forum for help. Please don’t try to get through this course programming in Notepad!

Working on the Lab

Once you have all of this working, you’ll need to check out your assignment. Assignments in this course will be distributed and submitted via the Swarthmore GitHub Enterprise instance. If you have never used the Swarthmore GitHub before, you should follow Tia Newhall’s GitHub Setup Guide. If you have taken CS31 or CS35 recently, you shouldn’t need to do this.

Once everything is configured, you can check out your assignment using the following command, replacing <username> with your Swarthmore username:

git clone git@github.swarthmore.edu:cs75-s25/ocaml1-<username>

Your job in this assignment is to open each of the .ml source files in your repository and complete the implementation tasks within. There are several files and you are encouraged to complete them in the following order:

  1. helloWorld.ml
  2. functions.ml
  3. linkedLists1.ml
  4. linkedLists2.ml
  5. breakfast.ml

Note that you’ll also be writing code in tests.ml. It’s likely that you’ll want to do that simultaneously with your edits to the other files.

Throughout these files, there are several calls to failwith using a string starting with “TODO”; there are also comments containing the string “TODO”. Your assignment will be complete when every one of these TODOs has been replaced with appropriate code.

It may take you a while to become accustomed to a new language, so be patient with yourself. You may wish to keep the OCaml Transition Guide open as you work on the assignment so you can use it to help you make the shift from the languages you know to OCaml.

As a clarification for those who may already know or choose to explore the features of the OCaml language: you are not permitted to use any of the following when you are completing your assignment:

If you don’t know what the above means, don’t worry! Everything you learned in lecture is fine to use in this assignment.

Submitting

It is not enough to push your work. In your repository, you will find a Python script called submit.py. In order to submit your lab assignment, it should be sufficient to run that script by typing python3 submit.py in your terminal. For this script to work correctly, you must have committed all uncommitted files in your repository and pushed your work so that your repository is in sync with your GitHub remote repository.

The aforementioned Python script is designed to create a Git tag: a name for a specific commit in your repository. (The script also performs a series of checks to help ensure that the tag you create contains what you likely think it contains.) The tag will be named using the words “submission”, the name of your assignment, and a version number. Your instructor will know that you have submitted your work because this tag will appear in your repository. If you need to resubmit your work to correct changes after receiving a grade, you can simply create new commits and then create another tag (preferrably with submit.py). At any given time, only your most recent outstanding submission will be graded.

In addition to submitting your work, you should fill out a brief questionnaire found here. In most cases, the questionnaire should take less than a minute.

If You Have Trouble…

…then please contact your instructor! The course forum is the preferred method, but you can reach out via e-mail as well. Good luck!