Skip to content

exercism/ocaml

Repository files navigation

Exercism OCaml Track

Exercism Exercises in OCaml

Contributing Guide

Contributions to the OCaml track (or any other part of Exercism) are very welcome!

Please see the contributing guide for overall guidance. The below notes contain a few details specific to Ocaml.

Getting started

Local setup

Prerequesites

  • OCaml 5.1
  • opam
  • make
git clone https://github.com/exercism/ocaml.git
cd ocaml
git submodule update --init --recursive

# see https://github.com/exercism/ocaml/blob/master/.travis/Dockerfile#L12
# might take a while
make install_deps

# Run generator tests
make test_generator

# Execute generator
make generate_exercises

# Run exercise tests
make test
Container setup

Prerequesites

  • VSCode
  • VSCode Remote Containers extension
  • Docker
git clone https://github.com/exercism/ocaml.git
cd ocaml
git submodule update --init --recursive

vscode .

# Inside container

# Run generator tests
make test_generator

# Execute generator
make generate_exercises

# Run exercise tests
make test

Adding an Exercise

The contributing guide provides guidance on how to add a new exercise, or port an existing exercise from another language track.

This is a brief guide, with specifics for the OCaml track.

Firstly, register the exercise in config json. The name of the exercise should go in the "slug" entry.

Then, write the exercise tests and proof of concept implementation. A folder layout for an exercise called "ocaml-exercise" is below.

└── templates
    └── ocaml-exercise
        ├── example.ml.tpl           (a proof of concept implementation)
        ├── ocaml_exercise.mli.tpl   (the interface definition for the exercise)
        ├── HINTS.md.tpl             (additional hints to anyone trying the exercise - optional)
        ├── Makefile                 (standard - copy this from any of the other Ocaml exercises)
        └── test.ml.tpl              (unit tests)

You can build your exercises from templates/ocaml-exercise to exercises/ocaml-exercise via the test generator:

make generate_exercises

This creates a folder exercises/ocaml-exercises that mirrors templates/ocaml-exercises and strips the .tpl extension:

└── templates
    └── ocaml-exercise
        ├── example.ml
        ├── ocaml_exercise.mli
        ├── HINTS.md
        ├── Makefile
        └── test.ml

Canonical test data

If you are implementing an existing test, there may be "canonical data" for it in the problem-specifications repository. An example: https://github.com/exercism/problem-specifications/blob/4531f54300f2a9f485a91a5dc0228be448b46b97/exercises/hello-world/canonical-data.json#L1-L12

You should base your tests off this data, in order to provide consistency across different language tracks.

Feedback

If you find this documentation is inaccurate or incomplete, or can be improved in any way, please don't hesitate to raise an issue or submit a pull request.

OCaml icon

The OCaml logo is released under the Attribution-ShareAlike 4.0 International license.