Installing, Using, and Editing OCaml or F# for CSE P505

Autumn 2016

Feedback welcome on this document. We will try to incorporate improvements as we receive them.

Introduction

For most of the course, we will use OCaml for our programming examples and homework assignments because (a) it is particularly well-suited for PL-related topics and (b) we have to pick something that gives us a common framework. However, we also support F#, which is a first-class citizen in .Net and Microsoft Visual Studio. It is very similar to OCaml, particularly for our limited purposes.

For either OCaml or F#, we have very basic needs: we are not going to write large programs, use unusual packages or libraries, rely on recent language additions, etc. So really any language version, any editor, any operating system, etc. should be fine. Probably the most “complicated” project-configuration issues we will encounter are (a) short Makefiles for describing the build of a handful of files and (b) lexer-generators and parser-generators (which we will give you) for concrete syntax for small languages we may have you implement. In both cases, we anticipate being able to provide alternate instructions or precompiled files so you can avoid such configuration details.

So really all you need is:

Alas, in the real world — since OCaml and F# are industrial-strength languages with the associated ecosystems — we are still left with a mind-numbing proliferation of choices, gotchas, operating systems, and all the usual software-installation headaches. Different students will choose different paths and we will do our best to help you, but we will focus in this document on a half-dozen or so installation approaches that your small course staff is familiar with and “knows works”. We will do our best to guide you in how to select among these half-dozen choices, and we are not opposed to Other Ways even if we are unable to help you as much with them.

Without further ado....

Choosing Between OCaml and F#

For our purposes, the languages are very similar, but there are just enough syntactic and feature differences, that we will likely provide different starter code for each language. In terms of the core intellectual challenge of the homeworks, neither language is “easier” — their cores are nearly identical and the cores are all we need.

Dan will use OCaml in class, on slides, etc. Supporting F# is new for him. So maybe that would lean you toward OCaml, but it really should not matter.

The real difference is comfort with your editor, operating system, and installation approach. The Internet assures us that both languages can be developed and run on all major operating systems. However, F# is a .Net language, so it tends to be more Windows-centric, and it has full support in Microsoft Developer Studio. Conversely, OCaml is harder to install on Windows than on other operating systems (though your instructor has done it many times).

In the end, if you are in doubt, choose OCaml and if you're already well-versed in Developer Studio, Windows, and .Net, then you will likely find F#'s tools and editors easier to deal with.

You don't have to use the same language for each homework, but switching means more time spent on installation.

Installation

Here are several viable choices for getting a compiler and related tools installed:

Running OCaml

In general, you can use ocaml to experiment on the fly, and ocamlc to compile an entire file at once. To exit ocaml's read-eval-print loop, either use Ctrl+D (may not work on all platforms) or "exit 0;;" (works anywhere).

For more information, see part III of the system manual: http://caml.inria.fr/pub/docs/manual-ocaml/.

On Windows, Dan uses the cygwin terminal to run ocamlc, ocaml, etc.

Editing OCaml Files

As usual, you will want to use an editor with support for indentation, syntax highlighting, etc. Because we are writing short programs for homework purposes, we do not need lots of modern features (e.g., auto-completion), but that may be a matter of taste.

If you are using F#, then you are probably going to use Visual Studio on Windows and whatever the suggested IDEs are for other operating systems.

If you are using OCaml, what Dan uses and “knows works” is Emacs with the Tuareg mode, so we provide detailed installation instructions that should work on any major operating system (and were recently tested on Windows). There are probably decent modes for other editors (vim? sublime? notepad++?) — feel free to tell us about them. Conversely, if you want minimal-but-sufficient notes on getting started with Emacs if you have never used it, let us know and we'll post some materials we have.

So... steps for using Emacs to edit OCaml files:


Valid CSS! Valid XHTML 1.1