Skip to content

Pilusx/ocamlhi

Repository files navigation

Logo

ocamlhi - Caml interpreter written in Haskell

Note

Last stable release License
If you want to test the interpreter, use the latest released version.

This package contains a simple interpreter of Caml with various algorithms such as static binding and static typing.

Note

Check DeepAI. The image was generated using Generative AI with the following prompt.

Camel with a tshirt containing a haskell logo, sitting in front of the computers.

Working with containers

Firstly, build the docker image:

    make build_docker

If you want to start the container and you have not already created it use:

    make run_docker

Otherwise attach to the container:

    make start_docker

If you want to delete the container run:

    docker container rm ocamlhi

Build the interpreter

    make build

Tests

GIF - Usage

Index Features
01 Simple types: char, double, int, string
02 Arithmetic, Comparisons
03 Conditional expressions (if then else)
04 Functions with multiple parameters, Recursion
05 Anonymous functions, Higher-order functions, Partial application
06 Static binding
07 Imperative programming (for loop, while loop)
08 Pattern matching
09 Operations on lists (head, map, tail)
10 Syntactic sugar for lists (x:y:tl)
11 Polymorphic lists: ('a -> 'a) list, 'a list list
12 Recursive data types ('a tree)
13 Static typing
14 Generalized algebraic data types: Either, Maybe, Pair
15 Records, References (assignments)
16 Tuples
17 Modules

To run the tests, use one of the following:

    make test
    python3 unittests.py [--print_failed]
    ./ocamlhi -I tests/stdlib -I tests/good 01_Constants.ml

Tip

If the output is "Killed" you probably have exceeded timeout (timeout = 1s). You may try to run the test manually (without using Python).

You can also compare the results with the original OCaml interpreter (v.4.05.0). Unfortunately, opam cannot be used during building of the image. Thus you have to install it before testing.

    make install_ocaml
    make test_ocaml

You can test the style of the source code by using:

    make install_haskell
    make test_style

Grammar changes

If you need to update the grammar you can:

  1. Modify the ocaml.fc file.
  2. Run make bnfc
  3. Resolve changes manually.

Out of scope / Possible extensions

  • Be 'compatible' with Ocaml API.
  • Fix static typing. (aliases)
  • Add private module members.
  • Add a garbage collector.
  • Integer emulation... Is 'int' bignum in ocaml?
  • Extend modules. Implement 'include' and 'open'.
  • Implement classes (object-oriented programming).
  • Implement multithreading and synchronization.
  • Implement lazy variables.
  • Implement catching exceptions. (raise / catch)
  • Implement exhaustiveness checks for pattern matching.
  • Implement recursive module signatures.
  • Implement a command line interpreter (REPL).

References

Referenced papers