|
Objective Caml, also known as OCaml or O'Caml for short, is an advanced programming language
that is part of the ML family. It is developed and
distributed as Open-source by
INRIA.
Ocaml was created in 1996 as a successor to Caml Light. Its authors
include Xavier Leroy, Jerome Vouillon and Damien Doligez.
CAML originally stood for Categorical Abstract Machine Language. OCaml
has not been based on this abstract machine for a long time.
OCaml shares the functional and
imperative features of ML, but contains
object-oriented concepts and some minor
syntax differences.
Features
Performance distinguishes OCaml from other languages in the ML
family. The runtime system was designed to be fast, efficient, and
rather frugal in memory.
Ocaml provides a bytecode compiler, a script interpreter or toplevel evaluation loop,
and an
optimizing native code compiler. The code generated by the
native code compiler is typically comparable to C/C++
in efficiency.
See for instance The Computer Language Shootout Benchmarks (http://shootout.alioth.debian.org/).
Powerful features of the language include a static
type system, type inference,
parametric polymorphism, tail recursion,
pattern matching,
first class lexical closures,
functors (parametric modules), exception handling, and
incremental generational automatic garbage collection.
It also has a quite concise syntax.
The object system provides
for multiple inheritance, object construction directly (by specifying methods for
a unique object) or from classes, and structural subtyping
(objects are of compatible types if their methods are compatible, regardless of what was
inherited from what).
OCaml features are pragmatically balanced between expressivity and new features
on the one side and ease of interfacing with existing systems and libraries and
efficiency on the other side. Ocaml contains support for familiar functions
such as printf, and a foreign function interface which permits
easy linking with C primitives, including language support for efficient
numerical arrays in formats compatible with both C and
FORTRAN.
The OCaml distribution includes a powerful preprocessor (which permits syntactical extensions),
a debugger (which includes the ability to step backwards in time when investigating an error),
a documentation generator, a profiler,
and numerous general purpose libraries. The compiler is available for a range of platforms, including Unix, Windows, and Macintosh, with native code generation for all major architectures (IA32, PowerPC, AMD64, Sparc, IA64, Alpha, HP/PA, MIPS, StrongARM), thus providing good portability.
Uses
OCaml is used in a wide range of applications, including
theorem proving and computer program analysis. It is
also used in applications such as MLDonkey (a popular P2P program supporting
multiple networks) and the Unison File Synchronizer (http://www.cis.upenn.edu/~bcpierce/unison/).
Programs implemented in Ocaml have won prizes several times in the
ICFP programming contest.
Ocaml is used as an introductory language in many universities, including
EPITA, École Normale Supérieure, Caltech, Brown University, and the University of Pisa.
See also
External links
Code examples
Hello World
let _ = print_endline "Hello world!"
99 Bottles of Beer
open Printf
let bottles = function
| 0 -> "no more bottles of beer"
| 1 -> "1 bottle of beer"
| n -> sprintf "%d bottles of beer" n
let verse n =
let current = bottles n and next = bottles (n - 1) in
let first_line = sprintf "%s on the wall, %s.\n" current current in
let second_line = "Take one down, pass it around,\n" in
let third_line = sprintf "and there's %s on the wall!\n" next in
first_line ^ second_line ^ third_line
let sing_song () =
for n = 99 downto 1 do
print_endline (verse n)
done;;
sing_song ()
|