Ocaml

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. 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

Computer Science

Natural Science

The OCaml language is also widely used in physics, chemistry, biology and, more recently, bioinformatics: Several example programs demonstrating the use of OCaml in scientific computing are available here.

Education

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 Prparatoires (Preparation Courses), for students who choose to study Computer Science (and has almost replaced Pascal for that).

Miscellaneous

Many commonly-used programs have been written in OCaml:
  • MLDonkey (a popular P2P program supporting multiple networks)
  • Unison (a file synchronizer)
as well as many fun programs:

See also

External links

Code examples

Hello World

    print_endline "Hello world!";; 

Birthday Paradox

The following is an OCaml script which calculates the number of people who need to be in a room before the probability of two sharing the same birthday becomes larger than 50% (the so-called birthday paradox). It also demonstrates OCaml's use as a scripting language. On a unix-like machine, save this to a file, chmod it to be executable (chmod 0755 birthday.ml) and run it directly 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    else      loop p' (i+1) ;;  loop 1.0 2 

 

<< PreviousWord BrowserNext >>
george hamilton gordon
obe
cbe
soho
british honours system
electroporation
freddie prinze
shiraz, iran
shiraz grape
symbiosis
cymbeline
shakespeare's late romances
alpine skiing at the 2002 winter olympics
biathlon at the 2002 winter olympics
cross country skiing at the 2002 winter olympics
figure skating at the 2002 winter olympics
freestyle skiing at the 2002 winter olympics
luge at the 2002 winter olympics
orlando bloom
nordic combined at the 2002 winter olympics
short track speed skating at the 2002 winter olympics
ski jumping at the 2002 winter olympics
snowboarding at the 2002 winter olympics
speed skating at the 2002 winter olympics
bobsleigh at the 2002 winter olympics
new england digital
dissociative identity disorder
joseph banks
john galsworthy
joseph cardinal ratzinger
john bunyan
sn 1604
jon appleton
supernova remnant
synclavier
dengue fever
finger millet
gas sculpture
berengar of tours
planetary nebula
decss
black's law dictionary
muckleshoot
banksia