Previous Contents Next
Chapter 9 The toplevel system (ocaml)

This chapter describes 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, compile and evaluate them, then prints the inferred type and result value, if any. The system prints a # (sharp) prompt before reading each phrase.

Input to the toplevel can span several lines. It is terminated by ;; (a double-semicolon). The toplevel input consists in one or several toplevel phrases, with the following syntax:
toplevel-input ::= { toplevel-phrase } ;;
toplevel-phrase ::= definition
  | expr
  | # ident  directive-argument
definition ::= let [rec] let-binding  { and let-binding }
  | external value-name :  typexpr =  external-declaration
  | type-definition
  | exception-definition
  | module module-name  [ : module-type ] =  module-expr
  | module type