Installation & Setup

Prerequisites

You need OCaml = 4.08 and optionally GNU Make for batch builds.

macOS

brew install ocaml opam
opam init
eval $(opam env)

Ubuntu / Debian

sudo apt update
sudo apt install ocaml opam make
opam init
eval $(opam env)

Windows (WSL recommended)

# Inside WSL (Ubuntu)
sudo apt install ocaml opam make
opam init
eval $(opam env)

Verify

ocaml -version
# Should print: The OCaml toplevel, version 5.x.x

Clone & Build

git clone https://github.com/sauravbhattacharya001/Ocaml-sample-code.git
cd Ocaml-sample-code

# Build all programs
make

# Build and run all programs
make run

# Clean build artifacts
make clean

Run Individual Files

# Compile and run a single file
ocamlopt -o factor factor.ml
./factor

# Or use the interactive REPL
ocaml
#use "factor.ml";;

Docker

No local OCaml installation needed — run everything in a container:

# Build the image
docker build -t ocaml-samples .

# Run all examples
docker run --rm ocaml-samples

# Run a single example
docker run --rm ocaml-samples mergesort