package ppx_include

  1. Overview
  2. Docs
Include OCaml source files in each other

Install

Dune Dependency

Authors

Maintainers

Sources

v1.1.tar.gz
sha256=c8857dd25ec7903faac8b9d33ad51adea305a22c765090b18b7a92f2c8458668
md5=83f647db794cad43fad29bc95a23233b

README.md.html

[%%include]

include is a syntax extension that allows to include an OCaml source file inside another one.

include requires OCaml 4.02 or later.

Installation

include can be installed via OPAM:

$ opam install ppx_include

Usage

In order to use include, require the package ppx_include.

Syntax

The structure item [%%include "file.ml"] or signature item [%%include "file.mli"] is replaced with the structure or signature items inside file.ml or file.mli. Whether the file is parsed as an interface or an implementation depends on the context of the [%%include] node; the extension is immaterial. The file can be located anywhere in the OCaml include path.

This can be most useful if you want to have the contents of recursive modules in several files:

module rec A : sig [%%include "a.mli"] end = struct [%%include "a.ml"] end
and B : sig [%%include "b.mli"] end = struct [%%include "b.ml"] end

Buildsystem integration

If your buildsystem uses separate source and build trees (like ocamlbuild does), include will not be able to find the included files. Since it is not possible to use existing mechanisms, such as ocamldep, to provide the dependencies to the buildsystem, it is necessary to specify dependencies manually.

ocamlbuild

For ocamlbuild, the myocamlbuild.ml file should look like this:

open Ocamlbuild_plugin

let () = dispatch (
  function
  | After_rules ->
    dep ["file:src_test/test_ppx_include.ml"]
        ["src_test/a.mli"; "src_test/b.mli"; "src_test/a.ml"; "src_test/b.ml"]
  | _ -> ())

License

include is distributed under the terms of MIT license.

OCaml

Innovation. Community. Security.