Install
Start hereYou need opam, OCaml’s package manager, and OCaml 5.5 or later. wiretype brings dune, the build tool, with it.
1. Install opam
Section titled “1. Install opam”brew install opambash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"winget install Git.Git OCaml.opamwiretype should work on Windows, but it is not tested there. If something fails, WSL gives you a Linux to follow the Linux steps in.
2. Set up OCaml
Section titled “2. Set up OCaml”opam initAnswer yes when it offers to set up your shell. This installs the latest OCaml, which takes a few minutes. Then let this terminal see it – a new terminal does by itself:
eval $(opam env)(& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }Already had opam?
Check ocaml -version. If it is older than 5.5, make a switch – an
environment of its own – with the latest OCaml:
opam switch create wiretype ocaml-base-compilereval $(opam env)3. Install wiretype
Section titled “3. Install wiretype”opam repo add hypha https://github.com/hyphatech/opam-repository.gitopam install wiretype ppx_wiretype| Package | What it is |
|---|---|
wiretype |
descriptions: reading, writing, bounds, kinds, schemas; links Ptime, Mtime and Uuidm alone |
ppx_wiretype |
[@@deriving wiretype], which writes a type’s description |
A program that only writes its descriptions by hand needs wiretype alone.
4. Name it in dune
Section titled “4. Name it in dune”A program names the libraries it uses in its dune file, and the deriver
as a preprocessor:
(executable (name main) (libraries wiretype) (preprocess (pps ppx_wiretype)))A description that names a time or a UUID – a Ptime.t, an
Mtime.Span.t or a Uuidm.t – needs that library in libraries too:
ptime, mtime or uuidm.
Check it worked
Section titled “Check it worked”$ ocaml -version$ opam list wiretype ppx_wiretypeThe first says 5.5 or later. The second lists both packages with a version,
not --, under Installed.
Your editor
Section titled “Your editor”For completion, types on hover and errors as you type, install the language server, then the OCaml Platform extension in VS Code – or the OCaml support of your editor:
opam install ocaml-lsp-serverThe quick start writes a first description, next.
