module Topfind : sig val predicates : string list ref val add_predicates : string list -> unit val syntax : string -> unit val standard_syntax : unit -> unit val revised_syntax : unit -> unit val don't_load : string list -> unit val don't_load_deeply : string list -> unit val load : string list -> unit val load_deeply : string list -> unit val reset : unit -> unit end
The Topfind module is part of the "findlib" package. The module depends on the presence of a toploop. When building a toploop, it is automatically linked in if "findlib" is linked in, e.g.
ocamlfind ocamlmktop options -package findlib -linkpkg options
When the platform supports DLLs, another possibility to get a toploop with findlib directives is to load the file "topfind" (normally installed in the standard library directory):
~ > ocaml Objective Caml version 3.04 # #use "topfind";; Findlib has been successfully loaded. Additional directives: #require "package";; to load a package #list;; to list the available packages #camlp4o;; to load camlp4 (standard syntax) #camlp4r;; to load camlp4 (revised syntax) Topfind.reset();; to force that packages will be reloaded - : unit = () # _
This works even in scripts (but the startup message is suppressed in this case).
The module is not thread-safe; if used in a multi-threaded script, all packgage loading must have happened before the first thread forks.
The Topfind module contains some functions simplifying package loading in scripts. Most important, there is a new directive "#require" for the same purpose.
The Topfind module needs some initialization, in particular the predicates variable needs to be set, and the packages already compiled into the toploop needs to be declared by the don't_load function. If the toploop has been built by ocamlfind[Command-line interface of the Package manager], the necessary initialization is automatically compiled in.
val predicates : string list ref
The variable contains the set of predicates that is assumed when packages are loaded.
val add_predicates : string list -> unit
This function adds the passed predicates predlist to the variable predicates.
val syntax : string -> unit
This function emulates the -syntax command line switch of ocamlfind.
val don't_load : string list -> unit
Declares the packages enumerated in pkglist as being linked into the toploop.
val don't_load_deeply : string list -> unit
Declares the packages enumerated in pkglist and all direct and indirect ancestors as being linked into the toploop.
val load : string list -> unit
The packages enumerated in pkglist are loaded in turn; packages that have already been loaded or that have been declared as linked in are skipped.
val load_deeply : string list -> unit
The packages enumerated in pkglist and all direct or indirect ancestors are loaded in topological order; packages that have already been loaded or that have been declared as linked in are skipped.
val reset : unit -> unit
This function causes that Topfind forgets that any package has already been loaded. Infomation about packages linked into the toploop remain intact. The effect of this function is that all dynamically loaded packages will be loaded again when load, load_deeply functions, or the #require directive are executed.
#require "package-name-list";;
The argument of the directive is a list of package names, separated by commas and/or whitespace. The directive has the same effect as load_deeply, i.e. the listed packages and all direct or indirect ancestors are loaded in topological order; packages that have already been loaded or that have been declared as linked in are skipped.