Description of the language
(From the official website)
Objective Caml belongs to the ML family of programming languages (see MlLanguage) and has been implemented at INRIA Rocquencourt within the "Cristal project" group. Since ML's inception in the late seventies, there has been a continuous line of research at INRIA devoted to implementations and improvements of ML. Objective Caml owes a lot to the original core ML language and to our first Caml implementation (1985-1990). A new byte-coded implementation called Caml Light was developed in the early nineties. The language Caml Light is still in use, especially for education. The language was renamed Objective Caml after the incorporation of a sophisticated module system and an object-oriented layer.
As all dialects of ML, Objective Caml possesses:
First-class functions (see FirstClassFunctions): functions can be passed to other functions, received as arguments or returned as results.
- A powerful type system with parametric polymorphism and type inference: functions may have polymorphic types. It is possible to define a type of collections parameterized by the type of the elements, and functions operating over such collections. For instance, the sorting procedure for arrays is defined for any array, regardless of the type of its elements.
- User-definable data-types and pattern matching: the user can define new recursive data-types as a combination of record and variant types. More importantly, functions over such structures can be defined by pattern matching: a generalized case statement that allows the combination of multiple tests and multiple definitions of parts of the argument in a very compact way.
- Exceptions for error reporting and non-local control structures.
- Automatic memory management.
In addition, Objective Caml features:
- A sophisticated module system: program phrases can be grouped into structures, which can be named and nested. Signatures are type specifications for structures; they can be used to hide some of the structure components or abstract over some type components. Functors, that is, functions from structures to structures, support parameterized modules.
- An expressive class-based object-oriented layer that includes traditional imperative operations on objects and classes, multiple inheritance, binary methods, and functional updates.
The Objective Caml implementation comes with general purpose libraries (arbitrary precision arithmetics, multi-threading, a toolkit for graphical user interfaces, etc.) and a Unix-style programming environment including a replay debugger and a time profiler. Objective Caml programs can easily be interfaced with other languages, in particular with other C programs or libraries. The implementation is targeted towards separate compilation of stand-alone applications, although interactive use via a read-eval-print loop is also supported. Both compilation to byte-code (for portability) and to native assembly code (for performance) are supported. The native code compiler generates very efficient code (see Doug Bagley's Computer Languages Shootout for an extensive example http://www.bagley.org/~doug/shootout/craps.shtml), complemented by a fast, unobtrusive incremental garbage collector. The implementation runs on most Unix platforms (Linux, Digital Unix, Solaris, IRIX), under Windows 95 and NT, and on the Macintosh.
So what is Ocaml useful for ?
Since Objective Caml is a high-level general purpose programming language, it has a very wide range of applications, except where low-level programming is needed. For these needs, it can still call C functions and be called back from C.
Basically, wherever C++ or Java apply, Ocaml can handle the task, with the advantages that ML languages offer, that is safety, (very) high speed, functional languages' expressiveness, and great code clarity.
The Ocaml development environment includes :
- a toplevel interpreter
- a bytecode compiler and a virtual machine
- a very efficient native code compiler
- a powerful preprocessor with which one can extend the grammar of the language: ocamlp4
- an extensive library and many third-party packages
- a "replay" debugger that can go to a point back in time (a very powerful feature, yet one has to use a debugger far less often in functional languages)
- tools for the generation of lexers and parsers
- an automatic documentation generator similar to javadoc : ocamldoc
- a static exception checker to help find uncaught exceptions : ocamlexc
- modes for Emacs, vim, Nedit and a plugin for Visual Sudio. An IDE exists for Unix/Linux OSes : Cameleon.
- last but not least, support through the official caml mailing list and other forums.
See also CategoryLanguage, FunctionalLanguages, MultiParadigmLanguages, HighLevelLanguages,
A personal view of an ObjectiveCaml programmer on the language in comparison with Standard ML (MlLanguage).
