Go to main content

man pages section 1: User Commands

Exit Print View

Updated: Wednesday, February 10, 2021

ocaml (1)


ocaml - The Objective Caml interactive toplevel


ocaml [ options ] [ object-files ] [ script-file ]


OCAML(1)                    General Commands Manual                   OCAML(1)

       ocaml - The Objective Caml interactive toplevel

       ocaml [ options ] [ object-files ] [ script-file ]

       The  ocaml(1)  command  is the toplevel system for Objective Caml, that
       permits interactive use of the Objective Caml system  through  a  read-
       eval-print loop. In this mode, the system repeatedly reads Caml phrases
       from the input, then typechecks,  compiles  and  evaluates  them,  then
       prints  the inferred type and result value, if any. The system prints a
       # (sharp) prompt before reading each phrase.

       A toplevel phrase can span several lines. It is  terminated  by  ;;  (a
       double-semicolon). The syntax of toplevel phrases is as follows.

       The  toplevel  system  is started by the command ocaml(1).  Phrases are
       read on standard input, results are printed on standard output,  errors
       on standard error. End-of-file on standard input terminates ocaml(1).

       If  one  or  more object-files (ending in .cmo or .cma) are given, they
       are loaded silently before starting the toplevel.

       If a script-file is given, phrases are read  silently  from  the  file,
       errors  printed  on standard error.  ocaml(1) exits after the execution
       of the last phrase.

       The following command-line options are recognized by ocaml(1).

       -I directory
              Add the given directory to the list of directories searched  for
              source  and compiled files. By default, the current directory is
              searched first, then the standard library directory. Directories
              added  with  -I are searched after the current directory, in the
              order in which they were given on the command line,  but  before
              the standard library directory.

              If  the  given  directory starts with +, it is taken relative to
              the standard library directory. For  instance,  -I +labltk  adds
              the  subdirectory  labltk  of the standard library to the search

              Directories can also be  added  to  the  search  path  once  the
              toplevel is running with the #directory directive.

       -init file
              Load  the given file instead of the default initialization file.
              The default file is .ocamlinit in the current  directory  if  it
              exists, otherwise .ocamlinit in the user's home directory.

              Labels  are not ignored in types, labels may be used in applica-
              tions, and labelled parameters can be given in any order.   This
              is the default.

              Do  not  compile  assertion  checks.  Note that the special form
              assert false is always compiled because it is typed specially.

              Ignore non-optional labels in types. Labels cannot  be  used  in
              applications, and parameter order becomes strict.

              Do not display any prompt when waiting for input.

              Do  not  include  the  standard library directory in the list of
              directories searched for source and compiled files.

              Check information path during type-checking, to make  sure  that
              all  types  are derived in a principal way.  When using labelled
              arguments and/or polymorphic methods, this flag is  required  to
              ensure  future  versions  of  the compiler will be able to infer
              types correctly, even if internal algorithms change.   All  pro-
              grams  accepted  in  -principal  mode  are  also accepted in the
              default mode with equivalent types, but different binary  signa-
              tures,  and  this  may slow down type checking; yet it is a good
              idea to use it once before publishing source code.

              Allow  arbitrary  recursive  types  during  type-checking.    By
              default,  only  recursive types where the recursion goes through
              an object type are supported.

              Turn bound checking  off  on  array  and  string  accesses  (the
              v.(i)ands.[i]  constructs).  Programs  compiled with -unsafe are
              therefore slightly faster, but unsafe: anything  can  happen  if
              the program accesses an array or string outside of its bounds.

              Print version string and exit.

       -w warning-list
              Enable  or  disable  warnings according to the argument warning-
              list.  See ocamlc(1) for the syntax of the argument.

       -warn-error warning-list
              Treat as errors the warnings enabled by  the  argument  warning-
              list.  See ocamlc(1) for the syntax of the argument.

       -help or --help
              Display a short usage summary and exit.

              If  set to iso_8859_1, accented characters (from the ISO Latin-1
              character set) in string and character literals are  printed  as
              is; otherwise, they are printed as decimal escape sequences.

       TERM   When  printing  error  messages, the toplevel system attempts to
              underline visually the location of the error.  It  consults  the
              TERM variable to determines the type of output terminal and look
              up its capabilities in the terminal database.

       See attributes(7) for descriptions of the following attributes:

       |Availability   | runtime/ocaml    |
       |Stability      | Volatile         |
       ocamlc(1), ocamlopt(1), ocamlrun(1).
       The Objective Caml user's manual, chapter "The toplevel system".

       This    software    was    built    from    source     available     at
       https://github.com/oracle/solaris-userland.    The  original  community
       source     was     downloaded      from       http://caml.inria.fr/dis-

       Further information about this software can be found on the open source
       community website at http://www.ocaml.org.