- array: a predefined container type of fixed length which is mutable and unlike lists supports efficient random access. See also list.
- bytecode: low-level, machine-independent code which results from the compilation of a program. In Ocaml programs can be compiled to bytecode using
ocamlc
and are run (usually transparently) by the OCaml virtual machine ocamlrun
. Bytecode executables are usually slower than their native code counterparts obtained with ocamlopt
.
- Caml: the generic name for the Caml lineage of languages developed at the INRIA-Rocquencourt, France. It belongs to the ML family of programming languages. Its current version is Objective Caml, which is the object of this web site, often referred to as OCaml or O'Caml.
- Caml Light: older version of Caml, which was superseded by OCaml.
- Camlp4: preprocessor for OCaml which manages syntax extensions of the language. The most commonly used command is
camlp4o
which loads the grammar for the regular syntax of OCaml plus the possible syntax extension modules which are passed on the command line.
- class: a definition of a set of objects (object-oriented programming). A class definition in OCaml results in a type which has the name of the class and a special function which can be used to create objects of that class (using the
new
keyword). Creating an object from a class is called class instanciation. Classes can be defined using one or several classes as a start point, this is called multiple inheritance. Each class has a class type, which defines the type of methods and values that are present and inheritable by other classes. It differs from the type of an object, which is a regular type that only defines the type of the public methods. When a class is created, its name defines both a class type and a regular type of the same name.
- closure: a function which, when executed, accesses the values (environment) which were accessible at the time it was defined in addition to the parameters, as opposed to the values which are accessible at the point where the function is being called. OCaml functions are closures. Internally, they are represented as a record containing a code pointer and the recorded environment (see there for details). Unlike objects which also associate data and functions, closures are created transparently by the compiler.
- compiler: a program which converts a program into another, written in a lower-level language such as bytecode or assembly code. The OCaml compilers are
ocamlc
and ocamlopt
.
- dynamic typing: as opposed to static typing which is used in OCaml, it consists in checking the consistency of data types along the execution of a program, possibly resulting in runtime errors. See also static typing.
- exception: a special semi-builtin type, which is denoted
exn
and can be extended using the exception
keyword. Exceptions can be raised (or "thrown" in other languages) and caught using pattern-matching to signal errors or to interrupt the normal flow of a program.
- expression: by default, a piece of program which represents a value or the computation of a value. There are also type expressions, class expressions, module expressions and so on, which are pieces of program which represent what their name says.
- Findlib: a system for managing OCaml libraries and their dependencies. It provides the
ocamlfind
code which is used as a front end to the OCaml compilers.
- function: an object which, when given some parameters or arguments, performs a computation and returns a result. In OCaml, functions can be manipulated like other values, so they can be passed as parameters to other functions. Executing a function is referred to as function application. OCaml functions can be anonymous. They allow partial application, i.e. passing only a subset of the parameters and returning a new function (a closure) which expects the remaining parameters. OCaml functions can be defined inside other functions, and embed some information that is available at the point where they are defined. Such functions which are associated with some (hidden) data are called closures. Procedures as defined in Pascal are simply functions which return the value of type unit, denoted ().
- GODI: a source-based package management system for OCaml development. GODI downloads selected packages and their dependencies, compiles them and installs them. GODI currently runs on Linux, Windows (Cygwin), MacOS X, Solaris, FreeBSD, NetBSD and HP-UX. GODI Homepage
- laziness: in programming languages, lazy evaluation consists in deferring computations until the result of the computation is really needed. It differs from functions because a regular function performs its computation everytime it is called, whereas a lazy computation is performed at most once, since it stores its result. OCaml provides support for lazy computations, although they are not the default as in Haskell.
- library: a compiled set of OCaml modules which is grouped into one file and can be used by other programs. Bytecode libraries end in
.cma
and native code libraries end in .cmxa
. As opposed to compilation units or object files (.cmo
and .cmx
), their name does not define a module. OCaml native code libraries are always statically linked, which does not prevent from using C dynamically-linked libraries.
- list: a central immutable data type in OCaml which is accessible only from one end. Although it has a special syntax, a list type can easily and efficiently be redefined using a sum type (see variants). For instance,
[]
is the empty list and [1;3;7]
is a list of ints and can as well be written as 1 :: (3 :: (7 :: []))
. See also array.
- module: a collection of definitions which can be values, types or submodules. Each implementation file (
.ml
suffix) automatically defines a module, and each interface file (.mli
suffix) is optional and can be used to restrict the visibility of module items.
- object (object-oriented programming): an object is a value that contains some private data and provides some functions called methods, which constitute the interface between the internal data of the object and the code that uses the object. In OCaml, an object may be created from a class definition or not.
- record: a value which belongs to a kind of type which contains a fixed number of labelled fields. It is the equivalent of records in Pascal and structs in C. For instance
type point = { x : int; y : int }
defines a record type with two fields x
and y
.
- object: (a) a value which has data and methods as in object-oriented programming. An object can be defined using a class, or not in which case it is called an immediate object. See class. (b) simply any OCaml value.
ocaml
: the command which starts an interactive toplevel session or reads, compiles and execute a given source file.
ocamlc
: the OCaml bytecode compiler. Generated code is machine-independent and executed by ocamlrun
.
ocamlfind
: See Findlib.
ocamlopt
: the OCaml native code compiler. It produces optimized, architecture-dependent code.
ocamllex
: a tool which converts a lexer definition into an efficient OCaml program. It is used to convert a stream of characters into a stream of user-defined tokens. Ocamllex is often used in conjunction with Ocamlyacc. Ocamllex and Ocamlyacc are similar to the Lex/Flex and Yacc/Bison tools for C and related languages.
ocamlrun
: the OCaml bytecode interpreter or virtual machine.
- static typing: the fact that the type of each expression is determined during the compilation of the program. OCaml programs are statically typed, which results in an efficient representation of runtime data.
ocamlyacc
: a parser generator which converts a given grammar into an OCaml program. See ocamllex
.
- pattern matching: in OCaml and the ML family of languages, pattern matching is a mechanism to test the structure of data and extract some elements. Although it also refers to search for patterns in strings using regexps, this is not the meaning which is usually implied by OCaml programmers. For example, some data of type
int option
can be read using the match-with construct:
match data with
None -> print_endline "Sorry, no data"
| Some str -> print_endline ("data = " ^ str)
- polymorphism: possibility of writing code which can be used for the manipulation of different types. This is also known as genericity. In OCaml, the kind of polymorphism which is used is known as parametric polymorphism as opposed to ad hoc polymorphism. For instance, the standard function
List.iter
is polymorphic since it operates over a list containing elements of any type.
- syntax: the way the program is structured according to a given grammar. In OCaml, it excludes the type checking and all the subsequent steps of the compilation. Camlp4 is a tool which allows the modification of the syntax of OCaml.
- type: a set of possible values. OCaml provides many ways of defining types, and the type of each expression is defined during the compilation. See type inference.
- type inference: the action that the compiler performs when it guesses the type of each expression of a program. In OCaml, it is normally not required to specify the type of each expression or variable, the compiler is able to figure it out by itself.
- variants: classic or polymorphic variants are the items which belong to a sum type. This is a way of grouping data of different structure under the same type. For instance, the predefined
'a option
type can be used to represent data which are possibly not initialized: None
would be the equivalent of a null pointer in C whereas Some "parameter"
would signify the presence of a value, here given as a string.