Opam
Opam is the package manager for OCaml.
Pin all the *.opam in a repo to a specific version without installing them
# -n = don't install .opam packages themselves
opam pin <path> --with-version <version> -n
Resources
Dune
Dune is a build system for OCaml.
Build a specific package
dune build -p <package>
Build some doc
dune build @doc
Run some tests
dune runtest
Build in watch mode and clear the screen on rebuilt
dune build -w --terminal-persistence=clear-on-rebuild
Resources
PPX
Summary
PPXs are a tool included in OCaml that allows you to rewrite the AST at compile time. It's very powerful but also very complicated.
Resources
OCaml
Note about exceptions
Exceptions can be a bit tricky to understand. It's hard to know when it is going to generate a StackOverflow error. With this two examples, we can understand how it behaves.
- This example is not going to generate an error as the handler is added arround the
g
function once.
let rec g x =
match x with
| Leaf x -> raise (Found x)
| Node (r, v) -> g r ; g v
let f x = try g x with Found x -> (* Do something *)
- However, this example is able to generate a StackOverflow error if the tree is too big. An handler is installed on
g
each time you call the function.
let rec g x =
match x with
| Leaf x -> raise (Found x)
| Node (r, v) -> try g r ; g v with Found x -> x
Resources
- Write a website with Dream: Dream is an OCaml web framework
- Realworld OCaml: tutorial about OCaml
- OCaml Programming Guidelines: OCaml guidelines for beter code
- Sherlocode: tool to search throught the OPAM codebase