Module Omod
Load installed modules in the toplevel.
See the Tutorial.
v0.0.2 — homepage
Omod
type silent=[|`Yes|`Loads|`No]The type for specifying silence. See
load.
val load : ?batch:bool -> ?silent:silent -> ?force:bool -> ?incs:bool -> ?init:bool -> ?dir:fpath -> string -> boolload ~batch ~silent ~force ~deps ~incs ~init ~dir "M"loads moduleMand returnstrueif the load was successful; init files may however have failed to load. The exact side effects of this function are described here. The optional parameters are as follows:batchiftruealternative load sequences error rather than interactively ask to select one. Defaults tonot !Sys.interactive.silentif`Allnothing is logged except errors. If`Loadsthen load sequences are not logged but other diagnostic messages may be logged. If`Noboth load sequences and diagnostic messages are logged. Defaults to`No.forceiftrueforce the reload of objects. Defaults tofalse.incsiftruedirectory includes should be added. Defaults totrue. See load semantics for details.initiftruetoplevel init files should be loaded, see the load semantics. Defaults totrue.diris currently ignored.
The full syntax for specifying the module to load is:
[PKG.]M(@VARIANT)*
Mis always the top level (compilation unit) module name to load.PKGconstrainsMto be found in packagePKG. Packages names are the name of directories just below omod's library directory (seeomod conf, andomod pkgfor a list).@VARIANT(repeatable) indicates that all ambiguities should be resolved according to variantVARIANT. This means that if an object can be found in multiple directories in a package directoryP, the one that is rooted in the hierarchy starting atP/VARIANTorP/@VARIANTwill be selected. If no ambiguity arises the parameter is ignored. See the tutorial for an example.
Assuming loads
This following can be used to assume that certain loads are already performed to prevent them from being (re)loaded by load invocations.
val assume_load : ?batch:bool -> ?silent:silent -> ?force:bool -> ?incs:bool -> ?init:bool -> ?dir:fpath -> string -> boolassume_loadis likeloadbut assumes the corresponding load sequence was already performed.
val assume_loads : ?batch:bool -> ?silent:silent -> ?force:bool -> ?incs:bool -> ?init:bool -> ?dir:fpath -> string list -> boolassume_loadsis likeloadsbut assumes the corresponding load sequence was already performed.
val assume_inc : fpath -> unitassume_inc dirassumes that pathdirhas been included.
val assume_obj : fpath -> unitassume_obj objassumes that file pathobjhas been loaded.
module Private : sig ... endPrivate definitions.
Tutorial
To use the toplevel helpers simply bring the Omod module in your scope: type or add the following line to your ~/.ocamlinit file.
#use "omod.top"If you are using ocamlnat you unfortunately need to #use another file:
#use "omod.nattop"It is also likely that opam's initialization bits in .ocamlinit to find the file to #use won't work. So you need to invoke ocamlnat with -noinit and indicate where the file to #use can be found. The following invocation should work:
rlwrap ocamlnat -I $OCAML_TOPLEVEL_PATH -noinitNow whenever you want to use a module named M invoke:
# Omod.load "M"This will recursively load its dependencies and toplevel init files. See load for more options and details.
If you are using omod in scripts you should also specify the package PKG where M should be found using the PKG.M syntax. This because a further package install could also install a module M resulting in a load ambiguity and your script no longer working.
If you run into multiple load sequence resolutions, Omod interactively asks to choose one of the possible sequences. Assuming you have the package ptime installed this is an example:
# Omod.load "Ptime_clock"since ptime provides an os clock for your operating system and a jsoo clock for your browser.
The ambiguity can be automatically resolved by specfiying the variant you want explicitely (see load for details) for example to directly request the OS clock you should issue:
# Omod.load "Ptime_clock\@os"In a script it would even be better to write:
# Omod.load "ptime.Ptime_clock\@os"Finally to list what was loaded by Omod type:
# Omod.status ()For information about how Omod locates packages, consult omod conf --help.
Load semantics and effects
- Loading an object means: load its dependencies, add its containing directory to the included directories (if
incsistrue), load the actual object and finally load its toplevel init file (ifinitistrueand the file exists, see below). - The toplevel init file of an object with basename
ois a file calledo_top_init.mlin the same directory as the object. - If an object is available both as a standalone file (
cmo,cmx) and in a library archive (cma,cmxs),Omodfavours loading the library archive. - If an interface dependency cannot be resolved to an implementation but does resolve to a compiled interface, the dependency is assumed to be a mli-only compilation unit and the directory of the compiled interface is added to the includes (if
incsis true). The initalization performed by
omod.topandomod.nattopassume (withincs:falseandinit:false) the following modules:utop.UTopifomod.topis#used inutop.ocaml.Toploopifomod.topis#used (not inutop).ocaml.Opttoploopifomod.nattopis#used. .
- Load sequences with
vmthreadvariants and objects of the formm.p.ext(profiling versions in the stdlib) are excluded from load sequence results. This reduces the load sequence from multiple occurences to a single candidate on many modules. - For
ocamlnatdependency analysis is made oncmxandcmxafiles, the suffixes of resulting objects is then mapped tocmxs. This assumes the corresponding files exist and their objects match.