Running OCaml code#
At its core, Camltac provides a way to run OCaml code within Rocq files. Following the tradition in the programming community, let’s print “Hello world!”:
Camltac recognizes OCaml syntax embedded between {{ and }}, and interprets it as top-level OCaml expressions (i.e. the same expressions that you would put in an .ml file). This means, for example, that you can use let bindings:
Here, hello and world cannot be accessed outside of the curly braces. To expose them, you need to define a module:
Camltac Module M := ocaml:{{ let hello = "Hello" let world = " from module M!" }}.
Camltac can also load external .ml files:
The Camltac Load "file.ml" command behaves equivalently to Camltac Module File := ocaml:(<contents of file.ml>).
Note
There is some setup required for Camltac Load to work with Dune, described in the How to use Camltac with Dune guide.