OCamlRV is an interpreter for a small subset of OCaml. It includes a parser, an error-reporting Hindley-Milner type inferencer, and an evaluator with support for recursive values and functions.
The project is implemented in OCaml and uses Dune as its build system.
- Integer, boolean, string,
unit, list, option, and tuple values - Arithmetic, comparison, equality, boolean, and unary operators
ifexpressions andmatchexpressions- Anonymous functions, function application, and partial application
- Pattern matching with variables, constants, lists, cons cells, tuples, and type annotations
- Non-recursive and recursive
letbindings, including mutually recursive bindings - Let-polymorphism and static type inference
- Parse-tree output and interpreter debug output
- OCaml
- Dune
- The dependencies listed in
OCamlRV.opam
For an opam-based setup, install the project dependencies with:
opam install . --deps-onlyBuild the project with Dune:
dune buildThe executable is available as bin/main.exe after building.
The runner reads a source file passed as its positional argument. At least one operation flag should be supplied:
dune exec -- main path/to/program.ml -interpretAvailable flags:
| Flag | Description |
|---|---|
-interpret |
Evaluate the program and print its output |
-inference |
Infer the types in the program and report type errors |
-dparsetree |
Print the parsed representation of the program |
-debug |
Enable interpreter debug output |
Several flags can be combined. For example, to inspect the parse tree and then interpret the example program:
dune exec -- main bin/example.ml -dparsetree -interpretThe runner can also read a program from standard input when no input filename is given:
printf 'let x = 2 + 3\n' | dune exec -- main -inferenceExample program:
let rec factorial n =
if n <= 1 then 1 else n * factorial (n - 1)
let () = print_int (factorial 5)Run the Dune test suite, including cram tests:
dune runtestThe Makefile provides common development targets:
make # Build the project
make fmt # Format and promote formatting changes
make lint # Run Dune lint checks
make zanuda # Run checks, tests, and ZanudaThe zanuda target uses Zanuda.
Property-based tests can be run through the QuickCheck executable:
dune exec -- quickchecklib/ast.ml- abstract syntax tree definitionslib/parser.ml- source parserlib/inferencer.ml- type inferencelib/interpreter.ml- evaluatorbin/main.ml- command-line runnermanytests.t/- typed and ill-typed example programstests/- unit and property-based test support
OCamlRV is distributed under the LGPL-3.0-or-later license. See
COPYING.LESSER for the license text.
Copyright 2024-2025 Viacheslav Sidorov and Danila Rudnev-Stepanyan.