Wiki

Clone wiki

helium / popl20 / Tutorial_Install

Tutorial 0: Compile and run

Requirements and installation

To install the interpreter, you will need:

  • Ocaml 4.07.1 or higher
  • OCamlbuild

If your system does not come with the latest OCaml compiler, try installing Opam and then using Opam to install the right version of the OCaml compiler.

To install Helium, download the sources, go the main directory, and run make.

Interpreter (interactive mode)

After the installation, you can run the REPL (that is, the interpreter in the interactive mode). Stay in the main Helium directory, and run the helium executable in the bin directory:

$ bin/helium
You will see the following:
[IO,RE]>
This means that the REPL is ready to evaluate an expression typed in by the user. The thing in square brackets is the list of effects that the expression can invoke (by default: input/output and runtime error). One cool thing about Helium is that you can install your own handlers in the REPL, and program with any effect as if it was native. This is useful, for example, to keep some stateful information between REPL requests.

Now, let's compute something. Type in 2+3;;. You will see this:

[IO,RE]> 2+3;;
5
: Int
Obviously, 2+3 is the expression, while ;; terminates the expression passed to the REPL. The system answers with the value of the expression and its type.

Loading a file

To load a source file, type in the following code and save it under the name Map.he

let rec map f xs =
  match xs with
  | []       => []
  | x :: xs' => f x :: map f xs'
  end
Now, we can use it in the REPL as follows:
[IO,RE]> import Map;;
[IO,RE]> open Map;;
[IO,RE]> map;;
<func> : ('c ->['b] 'a) ->['b] List 'c ->['b] List 'a

Interpreting a file

You can also interpret a file. Just pass its name as an argument to the interpreter. For example, add the following line to Map.he:

let _ = map printInt [1,2,3]
Now, we can run the program:
$ bin/helium Map.he
1
2
3

Updated