opam
opam switches are comparable to python's venvs: https://ocaml.org/docs/opam-switch-introduction
Show switches available to be installed:
opam switch list-available
- Show pre-releases as well:
opam switch list-available --all
- Show pre-releases as well:
Activate:
eval $(opam env)
Create new switch:
opam switch create <switch-name>
- Make a new switch with a specific compiler version (v5.1.1):
opam switch create 5.1.1
- Make a new switch with a specific compiler version (v5.1.1):
Delete a switch:
opam switch remove <switch-name>
- Default switch is named
default
??
- Default switch is named
List switches:
opam switch
Go to a switch:
opam switch <switch-name>
List installed packages:
opam list
oropam list -i
- List all available packages:
opam list -a
- List all available packages:
Change switch:
opam switch set <switch-name>
Install a package (to current switch):
opam install <package-name>
Remove a package:
opam remove <package-name>
Update package list:
opam update
Show version of an installed package:
opam info <package-name>
—
Many useful packages related to Coq are available only after adding this repo:
opam repo add coq-released https://coq.inria.fr/opam/released
Reference: https://opam.ocaml.org/doc/Usage.html
dune
General
- ocamllex has its own stanza:
- Run an executable:
dune exec ./lexer.exe
- dune adds a
.exe
extension to the executables that it makes
name
field ofexecutable
is the entry point.- Could be
main
formain.ml
- Could be
Starting off
# Initialize new project
dune init proj <proj-name>
dune build
dune exec
References: https://ocaml.org/docs/up-and-running
Both of the following are equivalent??
dune exec -- <cmd>
dune install; <cmd>
Don't treat a warning as error
(executable
(name lexer)
(flags (:standard (-warn-error -32))))
https://dune.readthedocs.io/en/latest/concepts/ocaml-flags.html
Useful packages/tools
- ocamlc: bytecode compiler
- ocamlopt: native code compiler
- merlin: ocaml code completion for text editors
- utop: like an enhanced ocaml REPL
- ocamlfind: ??
- jsofocaml: make web stuff from ocaml
- effectively allows running ocaml equivalent code as javascript
Jane Street libraries:
- base: a ocaml stdlib (minimal, lightweight, stable API, no dependencies)
- core: much more than base
- corekernel: more than base, less than core
- hardcaml: hardware designs with ocaml
Historical:
- oasis: an old build tool that was used before dune came along
- jbuilder: earlier name of dune
Loading base (Jane Street)
base is a package from janestreet.
# #use "topfind";;
# #require "base";;
# open Base;;
base < corekernel < core
The extra #
are needed.