Objective Caml (OCaml) is an advanced programming language which is a member of the ML family. It is developed and distributed as open-source by INRIA. OCaml was created in 1996 as a Caml Light successor by Xavier Leroy, Jerome Vouillon and Damien Doligez and others.

CAML originally stood for Categorical Abstract Machine Language. OCaml abandoned this abstract machine a long time ago.

OCaml shares the functional and imperative features of ML, but adds object-oriented concepts and has minor syntax differences.


Performance distinguishes OCaml from other ML languages. The runtime system was designed to be fast, efficient, and frugal in memory usage. OCaml provides a bytecode compiler, a script interpreter or toplevel evaluation loop, and an optimizing native code compiler. Code generated by the native code compiler is typically comparable to C/C++ in efficiency. See The Computer Language Shootout Benchmarks (http://shootout.alioth.debian.org/).

OCaml features: 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. Its syntax is quite concise. The object system supports multiple inheritance, direct object construction (by specifying methods for a unique object) or from classes, and structural subtyping, where (objects types are compatible if their methods are compatible, regardless of inheritance).

OCaml changes are pragmatically balanced between expressivity, new features, ease of interfacing with existing code and efficiency. Familiar functions such as printf. A foreign function interface for easy linking with C primitives is provided, including language support for efficient numerical arrays in formats compatible with both C and FORTRAN.

OCaml distribution components:

The compiler is available for many platforms, including Unix, Windows, and Macintosh. Excellent portability is ensured through native code generation support for major architectures.


Computer science

Natural science

OCaml is also widely used in physics, chemistry, biology and, more recently, bioinformatics:

Scientific computing OCaml examples (http://www.ffconsultancy.com/products/ocaml_for_scientists/complete/).


Ocaml is used as an introductory language in many universities, including:

OCaml is also used to teach Computer Science (mainly algorithms and complexity theories) in the French Classes Préparatoires (Preparation Courses), for students studying Computer Science (almost replacing Pascal).

Code examples

Hello World

  print_endline "Hello world!";;

Birthday paradox

OCaml may be used as a scripting language, as the following script calculates the number of people in a room before the probability of two sharing the same birthday becomes larger than 50% (the so-called birthday paradox).

On a unix-like machine, save it to a file, chmod to executable (chmod 0755 birthday.ml) and run it from the command line (./birthday.ml).

#!/usr/bin/ocamlrun ocaml

let size = 365. ;;

let rec loop p i =
  let p' = (size -. (float (i-1))) *. p /. size in
  if p' < 0.5 then
    Printf.printf "answer = %d\n" i
    loop p' (i+1) ;;
loop 1.0 2

Programs written in OCaml

Commonly used:

  • MLDonkey - a popular multi-network P2P program
  • Unison (http://www.cis.upenn.edu/~bcpierce/unison/) file synchronizer


See also

External links

es:Ocaml fr:Objective Caml it:Objective Caml ja:OCaml pl:Ocaml pt:OCaml ru:OCaml tr:Ocaml


  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)


  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Personal tools