Skip to content

Latest commit

 

History

History
90 lines (71 loc) · 1.95 KB

File metadata and controls

90 lines (71 loc) · 1.95 KB

https://ocaml.org/install

bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)"

[/usr/local/bin] -> opam package manager install path

opam init

update paths in ~/.zshrc update current shell env

eval $(opam env --switch=default)

Setup OCaml Development Environment

opam install dune merlin ocaml-lsp-server odoc ocamlformat utop dune-release

Link Merlin with editor

opam user-setup install

Using the REPL

utop

Exit the REPL

exit 0;;

Starting a new project

dune init project helloworld

All the metadata of your project is available in the file dune-project. Edit it to match your specific project.

We can build our program with dune build, which creates an executable file:

dune build

To run the program, we can use:

dune exec ./bin/main.exe

Or alternatively

dune exec helloworld

Configure OCamlFormat to format your code

echo "version = `ocamlformat --version`" > .ocamlformat

In addition to the editor, Dune is also able to drive OCamlFormat. Running this command will automatically format all files from your codebase:

dune fmt

Generate documentation with odoc

odoc is a tool that is not meant to be used by hand, just as compilers are not meant to be run manually in complex projects. Dune can drive odoc to generate documentation in the form of HTML, LaTeX, or man pages, from the docstrings and interface of the project's modules.

The following command will generate the documentation as HTML:

dune build @doc

# Unix or macOS
open _build/default/_doc/_html/index.html

Resources