OCaml 4.14.2 on FreeBSD 15.0-RELEASE
Table of Contents
1. Environment
uname -a
FreeBSD nexus 15.0-RELEASE FreeBSD 15.0-RELEASE releng/15.0-n280995-7aedc8de6446 GENERIC amd64
| Tool | Version | Source |
|---|---|---|
| OCaml | 4.14.2 | pkg install ocaml |
| opam | 2.4.1 | pkg install ocaml-opam |
| dune | not installed | opam install dune |
| zarith | 1.13 | pkg install ocaml-zarith |
| findlib | 1.9.6 | pkg install ocaml-findlib |
2. Installation
pkg install ocaml ocaml-opam opam init --bare opam switch create 4.14.2 opam install dune base64 alcotest
dune is not in FreeBSD ports — it must come from opam.
3. Lessons from the Transform Pipeline
The OCaml implementation at aygp-dr/transform-tool-ocaml exposed three spec gaps:
- Chain parser: parsed
:dat chain level, not per-step. Pattern matching on character ranges was clean, but the string splitting required manual buffer iteration (noStrin stdlib). - XOR codec: treated as involution (
f(f(x)) = xat byte level). The spec requires hex output, making it a bijection. reverse_pipeline: flipped direction on involutions. Harmless in OCaml (same function in both record fields) but wrong per spec.
All three were fed back into the spec.
3.1. What OCaml does well
Pattern matching for character-level codecs:
let rot13_char (c : char) : char = match c with | 'A' .. 'M' -> Char.chr (Char.code c + 13) | 'N' .. 'Z' -> Char.chr (Char.code c - 13) | 'a' .. 'm' -> Char.chr (Char.code c + 13) | 'n' .. 'z' -> Char.chr (Char.code c - 13) | _ -> c
string option for decode failure forces every call site to handle it.