Objective Caml
Encyclopedia
OCaml originally known as Objective Caml, is the main implementation of the Caml
programming language
, created by Xavier Leroy
, Jérôme Vouillon, Damien Doligez
, Didier Rémy and others in 1996. OCaml extends the core Caml language with object-oriented
constructs.
OCaml's toolset includes an interactive toplevel interpreter
, a bytecode
compiler
, and an optimizing native code compiler. It has a large standard library that makes it useful for many of the same applications as Python
or Perl
, as well as robust modular and object-oriented programming constructs that make it applicable for large-scale software engineering. OCaml is the successor to Caml Light. The acronym CAML originally stood for Categorical Abstract Machine Language, although OCaml abandons this abstract machine.
OCaml is a free
open source project managed and principally maintained by INRIA
. In recent years, many new languages have drawn elements from OCaml, most notably F# and Scala.
s and type-inferring
compilers. OCaml unifies functional
, imperative
, and object-oriented programming
under an ML-like type system. This means the program author is not required to be overly familiar with pure functional language paradigm in order to use OCaml.
OCaml's static type system can help eliminate problems at runtime. However, it also forces the programmer to conform to the constraints of the type system, which can require careful thought and close attention. A type-inferring compiler greatly reduces the need for manual type annotations (for example, the data type
of variables and the signature of functions usually do not need to be explicitly declared, as they do in Java
). Nonetheless, effective use of OCaml's type system can require some sophistication on the part of the programmer.
OCaml is perhaps most distinguished from other languages with origins in academia by its emphasis on performance. Firstly, its static type system renders runtime type mismatches impossible, and thus obviates runtime type and safety checks that burden the performance of dynamically typed languages, while still guaranteeing runtime safety (except when array bounds checking is turned off, or when certain type-unsafe features like serialization are used; these are rare enough that avoiding them is quite possible in practice).
Aside from type-checking overhead, functional programming
languages are, in general, challenging to compile to efficient machine language code, due to issues such as the funarg problem
. In addition to standard loop, register, and instruction optimizations
, OCaml's optimizing compiler employs static program analysis techniques to optimize value boxing and closure
allocation, helping to maximize the performance of the resulting code even if it makes extensive use of functional programming constructs.
Xavier Leroy
has stated that "OCaml delivers at least 50% of the performance of a decent C compiler", but a direct comparison is impossible. Some functions in the OCaml standard library are implemented with faster algorithms than equivalent functions in the standard libraries of other languages. For example, the implementation of set union in the OCaml standard library is asymptotically faster than the equivalent function in the standard libraries of imperative languages (e.g. C++, Java) because the OCaml implementation exploits the immutability of sets in order to reuse parts of input sets in the output (persistence
).
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
.
OCaml is particularly notable for extending ML-style type inference to an object system in a general purpose language. This permits structural subtyping, where object types are compatible, if their method signatures are compatible, regardless of their declared inheritance; an unusual feature in statically-typed languages.
A foreign function interface
for linking to C
primitives is provided, including language support for efficient numerical arrays in formats compatible with both C and FORTRAN
. OCaml also supports the creation of libraries of OCaml functions that can be linked to a "main" program in C, so that one could distribute an OCaml library to C programmers who have no knowledge nor installation of OCaml.
The OCaml distribution contains:
The native code compiler is available for many platforms, including Unix
, Microsoft Windows
, and Apple
Mac OS X
. Excellent portability is ensured through native code generation support for major architectures: IA-32
, IA-64
, AMD64
, HP/PA
; PowerPC
, SPARC
, Alpha
, MIPS
, and StrongARM
.
OCaml bytecode and native code programs can be written in a multithreaded
style, with preemptive context switching. However, because the garbage collector is not designed for concurrency, symmetric multiprocessing
is not supported. OCaml threads in the same process execute by time sharing only. There are however several libraries for distributed computing such as Functory and ocamlnet/Plasma (blog).
$ ocaml
Objective Caml version 3.09.0
#
Code can then be entered at the "#" prompt. For example, to calculate 1+2*3:
# 1 + 2 * 3;;
- : int = 7
OCaml infers the type of the expression to be "int" (a machine-precision integer) and gives the result "7".
can be compiled into a bytecode executable:
$ ocamlc hello.ml -o hello
or compiled into an optimized native-code executable:
$ ocamlopt hello.ml -o hello
and executed:
$ ./hello
Hello World!
$
or Java
languages' switch
element, though it is much more general.
# sum [1;2;3;4;5];;
- : int = 15
Another way is to use standard fold function that works with lists.
# sum [1;2;3;4;5];;
- : int = 15
, where for 1 person the probability is obviously 100%, for 2 it is 364/365, etc.) (answer = 23).
of natural numbers, with successor (succ) and addition (add). A Church numeral is a higher-order function that accepts a function and a value and applies to exactly times. To convert a Church numeral from a functional value to a string, we pass it a function that prepends the string to its input and the constant string .
In OCaml, the Num module provides arbitrary-precision arithmetic and can be loaded into a running top-level using:
The factorial function may then be written using the arbitrary-precision numeric operators =/, */ and -/ :
This function can compute much larger factorials, such as 120!:
The cumbersome syntax for Num operations can be alleviated thanks to the camlp4 syntax extension called Delimited overloading:
:
The LablGL bindings to OpenGL are required. The program may then be compiled to bytecode with:
$ ocamlc -I +lablGL lablglut.cma lablgl.cma simple.ml -o simple
or to nativecode with:
$ ocamlopt -I +lablGL lablglut.cmxa lablgl.cmxa simple.ml -o simple
and run:
$ ./simple
Far more sophisticated, high-performance 2D and 3D graphical programs are easily developed in OCaml. Thanks to the use of OpenGL, the resulting programs are not only succinct and efficient, but also cross-platform, compiling without any changes on all major platforms.
As an example: if at compile time it is known that a certain power function
is needed very frequently, but the value of is known only at runtime, you can use a two-stage power function in MetaOCaml:
As soon as you know at runtime, you can create a specialized and very fast power function:
The result is:
The new function is automatically compiled.
The private trading firm Jane Street Capital has adopted OCaml as its preferred language. http://cacm.acm.org/magazines/2011/11/138203-ocaml-for-the-masses/fulltext
Caml
Caml is a dialect of the ML programming language family, developed at INRIA and formerly at ENS....
programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
, created by Xavier Leroy
Xavier Leroy
Xavier Leroy is a French computer scientist and programmer. He is best known for his role as a primary developer of the Objective Caml system...
, Jérôme Vouillon, Damien Doligez
Damien Doligez
Damien Doligez is a French academic and programmer. He is best known for his role as a developer of the Objective Caml system, especially its garbage collector. He is research scientist at the French government research institution INRIA.- External links :*...
, Didier Rémy and others in 1996. OCaml extends the core Caml language with object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
constructs.
OCaml's toolset includes an interactive toplevel interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...
, a bytecode
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
, and an optimizing native code compiler. It has a large standard library that makes it useful for many of the same applications as Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
or Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
, as well as robust modular and object-oriented programming constructs that make it applicable for large-scale software engineering. OCaml is the successor to Caml Light. The acronym CAML originally stood for Categorical Abstract Machine Language, although OCaml abandons this abstract machine.
OCaml is a free
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
open source project managed and principally maintained by INRIA
Institut national de recherche en informatique et en automatique
The National Institute for Research in Computer Science and Control is a French national research institution focusing on computer science, control theory and applied mathematics.It was created in 1967 at Rocquencourt near Paris, part of Plan Calcul...
. In recent years, many new languages have drawn elements from OCaml, most notably F# and Scala.
Philosophy
ML-derived languages are best known for their static type systemType system
A type system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur...
s and type-inferring
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....
compilers. OCaml unifies functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...
, imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...
, and object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
under an ML-like type system. This means the program author is not required to be overly familiar with pure functional language paradigm in order to use OCaml.
OCaml's static type system can help eliminate problems at runtime. However, it also forces the programmer to conform to the constraints of the type system, which can require careful thought and close attention. A type-inferring compiler greatly reduces the need for manual type annotations (for example, the data type
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...
of variables and the signature of functions usually do not need to be explicitly declared, as they do in Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
). Nonetheless, effective use of OCaml's type system can require some sophistication on the part of the programmer.
OCaml is perhaps most distinguished from other languages with origins in academia by its emphasis on performance. Firstly, its static type system renders runtime type mismatches impossible, and thus obviates runtime type and safety checks that burden the performance of dynamically typed languages, while still guaranteeing runtime safety (except when array bounds checking is turned off, or when certain type-unsafe features like serialization are used; these are rare enough that avoiding them is quite possible in practice).
Aside from type-checking overhead, functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...
languages are, in general, challenging to compile to efficient machine language code, due to issues such as the funarg problem
Funarg problem
In computer science, the funarg problem refers to the difficulty in implementing first-class functions in stack-based programming language implementations....
. In addition to standard loop, register, and instruction optimizations
Compiler optimization
Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attributes of an executable computer program. The most common requirement is to minimize the time taken to execute a program; a less common one is to minimize the amount of memory occupied...
, OCaml's optimizing compiler employs static program analysis techniques to optimize value boxing and closure
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...
allocation, helping to maximize the performance of the resulting code even if it makes extensive use of functional programming constructs.
Xavier Leroy
Xavier Leroy
Xavier Leroy is a French computer scientist and programmer. He is best known for his role as a primary developer of the Objective Caml system...
has stated that "OCaml delivers at least 50% of the performance of a decent C compiler", but a direct comparison is impossible. Some functions in the OCaml standard library are implemented with faster algorithms than equivalent functions in the standard libraries of other languages. For example, the implementation of set union in the OCaml standard library is asymptotically faster than the equivalent function in the standard libraries of imperative languages (e.g. C++, Java) because the OCaml implementation exploits the immutability of sets in order to reuse parts of input sets in the output (persistence
Persistent data structure
In computing, a persistent data structure is a data structure which always preserves the previous version of itself when it is modified; such data structures are effectively immutable, as their operations do not update the structure in-place, but instead always yield a new updated structure...
).
Features
OCaml features: a statictype system
Type system
A type system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur...
, type inference
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....
,
parametric polymorphism, tail recursion,
pattern matching
Pattern matching
In computer science, pattern matching is the act of checking some sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact. The patterns generally have the form of either sequences or tree structures...
,
first class lexical closures
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...
,
functors (parametric modules), exception handling
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....
, and
incremental generational automatic garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
.
OCaml is particularly notable for extending ML-style type inference to an object system in a general purpose language. This permits structural subtyping, where object types are compatible, if their method signatures are compatible, regardless of their declared inheritance; an unusual feature in statically-typed languages.
A foreign function interface
Foreign function interface
A foreign function interface is a mechanism by which a program written in one programming language can call routines or make use of services written in another. The term comes from the specification for Common Lisp, which explicitly refers to the language features for inter-language calls as...
for linking to C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
primitives is provided, including language support for efficient numerical arrays in formats compatible with both C and FORTRAN
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...
. OCaml also supports the creation of libraries of OCaml functions that can be linked to a "main" program in C, so that one could distribute an OCaml library to C programmers who have no knowledge nor installation of OCaml.
The OCaml distribution contains:
- An extensible parser and macro language named Camlp4Camlp4Camlp4 is a software system for writing extensible parsers for programming languages. It provides a set of Objective Caml libraries that are used to define grammars as well as loadable syntax extensions of such grammars...
, which permits the syntax of OCaml to be extended or even replaced - Lexer and parser tools called ocamllex and ocamlyacc
- DebuggerDebuggerA debugger or debugging tool is a computer program that is used to test and debug other programs . The code to be examined might alternatively be running on an instruction set simulator , a technique that allows great power in its ability to halt when specific conditions are encountered but which...
that supports stepping backwards to investigate errors - Documentation generatorDocumentation generatorA documentation generator is a programming tool that generates documentation intended for programmers or end users , or both, from a set of specially commented source code files, and in some cases, binary files....
- Profiler — for measuring performance
- Numerous general purpose librariesLibrary (computer science)In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications....
The native code compiler is available for many platforms, including Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
, Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, and Apple
Apple Computer
Apple Inc. is an American multinational corporation that designs and markets consumer electronics, computer software, and personal computers. The company's best-known hardware products include the Macintosh line of computers, the iPod, the iPhone and the iPad...
Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
. Excellent portability is ensured through native code generation support for major architectures: IA-32
IA-32
IA-32 , also known as x86-32, i386 or x86, is the CISC instruction-set architecture of Intel's most commercially successful microprocessors, and was first implemented in the Intel 80386 as a 32-bit extension of x86 architecture...
, IA-64
Itanium
Itanium is a family of 64-bit Intel microprocessors that implement the Intel Itanium architecture . Intel markets the processors for enterprise servers and high-performance computing systems...
, AMD64
X86-64
x86-64 is an extension of the x86 instruction set. It supports vastly larger virtual and physical address spaces than are possible on x86, thereby allowing programmers to conveniently work with much larger data sets. x86-64 also provides 64-bit general purpose registers and numerous other...
, HP/PA
PA-RISC family
PA-RISC is an instruction set architecture developed by Hewlett-Packard. As the name implies, it is a reduced instruction set computer architecture, where the PA stands for Precision Architecture...
; PowerPC
PowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...
, SPARC
SPARC
SPARC is a RISC instruction set architecture developed by Sun Microsystems and introduced in mid-1987....
, Alpha
DEC Alpha
Alpha, originally known as Alpha AXP, is a 64-bit reduced instruction set computer instruction set architecture developed by Digital Equipment Corporation , designed to replace the 32-bit VAX complex instruction set computer ISA and its implementations. Alpha was implemented in microprocessors...
, MIPS
MIPS architecture
MIPS is a reduced instruction set computer instruction set architecture developed by MIPS Technologies . The early MIPS architectures were 32-bit, and later versions were 64-bit...
, and StrongARM
StrongARM
The StrongARM is a family of microprocessors that implemented the ARM V4 instruction set architecture . It was developed by Digital Equipment Corporation and later sold to Intel, who continued to manufacture it before replacing it with the XScale....
.
OCaml bytecode and native code programs can be written in a multithreaded
Thread (computer science)
In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...
style, with preemptive context switching. However, because the garbage collector is not designed for concurrency, symmetric multiprocessing
Symmetric multiprocessing
In computing, symmetric multiprocessing involves a multiprocessor computer hardware architecture where two or more identical processors are connected to a single shared main memory and are controlled by a single OS instance. Most common multiprocessor systems today use an SMP architecture...
is not supported. OCaml threads in the same process execute by time sharing only. There are however several libraries for distributed computing such as Functory and ocamlnet/Plasma (blog).
Code examples
Snippets of OCaml code are most easily studied by entering them into the "top-level". This is an interactive OCaml session that prints the inferred types of resulting or defined expressions. The OCaml top-level is started by simply executing the OCaml program:$ ocaml
Objective Caml version 3.09.0
#
Code can then be entered at the "#" prompt. For example, to calculate 1+2*3:
# 1 + 2 * 3;;
- : int = 7
OCaml infers the type of the expression to be "int" (a machine-precision integer) and gives the result "7".
Hello World
The following program "hello.ml":can be compiled into a bytecode executable:
$ ocamlc hello.ml -o hello
or compiled into an optimized native-code executable:
$ ocamlopt hello.ml -o hello
and executed:
$ ./hello
Hello World!
$
Summing a list of integers
Lists are one of the most fundamental datatypes in OCaml. The following code example defines a recursive function sum that accepts one argument xs. The function recursively iterates over a given list and provides a sum of integer elements. The match statement has similarities with C++C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
or Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
languages' switch
Switch statement
In computer programming, a switch, case, select or inspect statement is a type of selection control mechanism that exists in most imperative programming languages such as Pascal, Ada, C/C++, C#, Java, and so on. It is also included in several other types of languages...
element, though it is much more general.
# sum [1;2;3;4;5];;
- : int = 15
Another way is to use standard fold function that works with lists.
# sum [1;2;3;4;5];;
- : int = 15
Quicksort
OCaml lends itself to the concise expression of recursive algorithms. The following code example implements an algorithm similar to quicksort that sorts a list in increasing order.Birthday paradox
The following program calculates the smallest number of people in a room for whom the probability of completely unique birthdays is less than 50% (the so-called birthday paradoxBirthday paradox
In probability theory, the birthday problem or birthday paradox pertains to the probability that, in a set of n randomly chosen people, some pair of them will have the same birthday. By the pigeonhole principle, the probability reaches 100% when the number of people reaches 366. However, 99%...
, where for 1 person the probability is obviously 100%, for 2 it is 364/365, etc.) (answer = 23).
Church numerals
The following code defines a Church encodingChurch encoding
In mathematics, Church encoding is a means of embedding data and operators into the lambda calculus, the most familiar form being the Church numerals, a representation of the natural numbers using lambda notation...
of natural numbers, with successor (succ) and addition (add). A Church numeral is a higher-order function that accepts a function and a value and applies to exactly times. To convert a Church numeral from a functional value to a string, we pass it a function that prepends the string to its input and the constant string .
Arbitrary-precision factorial function (libraries)
A variety of libraries are directly accessible from OCaml. For example, OCaml has a built-in library for arbitrary precision arithmetic. As the factorial function grows very rapidly, it quickly overflows machine-precision numbers (typically 32- or 64-bits). Thus, factorial is a suitable candidate for arbitrary-precision arithmetic.In OCaml, the Num module provides arbitrary-precision arithmetic and can be loaded into a running top-level using:
The factorial function may then be written using the arbitrary-precision numeric operators =/, */ and -/ :
This function can compute much larger factorials, such as 120!:
The cumbersome syntax for Num operations can be alleviated thanks to the camlp4 syntax extension called Delimited overloading:
Triangle (graphics)
The following program "simple.ml" renders a rotating triangle in 2D using OpenGLOpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...
:
The LablGL bindings to OpenGL are required. The program may then be compiled to bytecode with:
$ ocamlc -I +lablGL lablglut.cma lablgl.cma simple.ml -o simple
or to nativecode with:
$ ocamlopt -I +lablGL lablglut.cmxa lablgl.cmxa simple.ml -o simple
and run:
$ ./simple
Far more sophisticated, high-performance 2D and 3D graphical programs are easily developed in OCaml. Thanks to the use of OpenGL, the resulting programs are not only succinct and efficient, but also cross-platform, compiling without any changes on all major platforms.
Fibonacci Sequence
The following code calculates the Fibonacci sequence of a number n inputed. It uses tail recursion and pattern matching.MetaOCaml
MetaOCaml is a multi-stage programming extension of OCaml enabling incremental compiling of new machine code during runtime. Under certain circumstances, significant speedups are possible using multi-stage programming, because more detailed information about the data to process is available at runtime than at the regular compile time, so the incremental compiler can optimize away many cases of condition checking etc.As an example: if at compile time it is known that a certain power function
Exponentiation
Exponentiation is a mathematical operation, written as an, involving two numbers, the base a and the exponent n...
is needed very frequently, but the value of is known only at runtime, you can use a two-stage power function in MetaOCaml:
As soon as you know at runtime, you can create a specialized and very fast power function:
The result is:
The new function is automatically compiled.
Other derived languages
- AtomCaml provides a synchronization primitive for atomic (transactional) execution of code.
- "Emily is a subset of OCaml that uses a design rule verifier to enforce object-capabilityObject-capability modelThe object-capability model is a computer security model based on the Actor model of computation. The name "object-capability model" is due to the idea that the capability to perform an operation can be obtained by the following combination:...
[ securityCapability-based securityCapability-based security is a concept in the design of secure computing systems, one of the existing security models. A capability is a communicable, unforgeable token of authority. It refers to a value that references an object along with an associated set of access rights...] principles." - F# is a Microsoft .NET language based on OCaml.
- Fresh OCaml facilitates the manipulation of names and binders.
- GCaml adds extensional polymorphism to OCaml, thus allowing overloading and type-safe marshalling.
- JoCamlJoCamlJoCaml is an experimental functional programming language derived from OCaml. It integrates the primitives of the join-calculus to enable flexible, type-checked concurrent and distributed programming.- External links :* *...
integrates constructions for developing concurrent and distributed programs. - OCamlDuce extends OCaml with features such as XML expressions and regular-expression types.
- OCamlP3l is a parallel programming system based on OCaml and the P3L language
Software written in OCaml
- FFTWFFTWFFTW, for "Fastest Fourier Transform in the West", is a software library for computing discrete Fourier transforms , developed by Matteo Frigo and Steven G. Johnson at the Massachusetts Institute of Technology....
– a software library for computing discrete Fourier transformDiscrete Fourier transformIn mathematics, the discrete Fourier transform is a specific kind of discrete transform, used in Fourier analysis. It transforms one function into another, which is called the frequency domain representation, or simply the DFT, of the original function...
s. Several C routines have been generated by an OCaml program named . - UnisonUnison (file synchronizer)Unison is a file synchronization program. It is used for synchronizing files between two directories, either on one computer, or between a computer and another storage device Unison is a file synchronization program. It is used for synchronizing files between two directories, either on one...
– a file synchronizationFile synchronizationFile synchronization in computing is the process of ensuring that computer files in two or more locations are updated via certain rules....
program to synchronize files between two directories. - Galax – an open source XQueryXQuery- Features :XQuery provides the means to extract and manipulate data from XML documents or any data source that can be viewed as XML, such as relational databases or office documents....
implementation. - MldonkeyMLDonkeyMLDonkey is an open source, multi-protocol, peer-to-peer file sharing application that runs as a back-end server application on many platforms. It can be controlled through a user interface provided by one of many separate front-ends, including a Web interface, telnet interface and over a dozen...
– a peer to peer client based on the EDonkey networkEDonkey networkThe eDonkey network is a decentralized, mostly server-based, peer-to-peer file sharing network best suited to share big files among users, and to provide long term availability of files...
. - GeneWeb – free open source multi-platform genealogy software.
- The haXe compiler – a free open source compiler for the haXeHaXehaXe is a versatile open-source high-level multiplatform programming language described on its website as a "universal language".It can produce:* Flash applications and games* Multi-platform client-side web applications* Apache CGI web applications...
programming language. - Frama-cFrama-CFrama-C stands for Framework for Modular Analysis of C programs. Frama-C is a set of interoperable program analyzers for C programs. Frama-C has been developed by Commissariat à l'Énergie Atomique et aux Énergies Alternatives and Inria...
– a framework for C programs analysis. - LiquidsoapLiquidsoapLiquidsoap is an audio programming language developed initially to produce audio and video source streams sent to an Icecast server. The difference with other available tools is that Liquidsoap interprets a dedicated script language, which makes it very versatile and adaptable to a lot of various...
– Liquidsoap is the audio stream generator of the Savonet project, notably used for generating the stream of netradios. http://savonet.sourceforge.net/ - CoccinelleCoccinelle (software)Coccinelle is a tool to match and transform the source code of programs written in the programming language C. Coccinelle was initially used to aid the evolution of Linux; with support for changes to library application programming interfaces such as renaming a function, adding a function...
– Coccinelle is a program matching and transformation engine that provides the SmPL language (Semantic Patch Language) for specifying desired matches and transformations in CC (programming language)C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
code. http://coccinelle.lip6.fr/ - CSIsat – a Tool for LA+EUF Interpolation.
- OrpieOrpieOrpie is a command-line reverse polish notation calculator written in OCaml by Paul Pelzl, a graduate student at the University of Michigan. It is open source and available for a wide variety of Unix-like operating systems.- External links :*...
– a command-line RPNReverse Polish notationReverse Polish notation is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position. It is also known as Postfix notation and is parenthesis-free as long as operator arities are fixed...
calculator - CoqCoqIn computer science, Coq is an interactive theorem prover. It allows the expression of mathematical assertions, mechanically checks proofs of these assertions, helps to find formal proofs, and extracts a certified program from the constructive proof of its formal specification...
– a formal proof management system. - OcsigenOcsigenOcsigen is a Web application framework based on concepts derived from recent research in the field of programming languages, namely that of continuation-based web programming...
– web development framework - Mirage – operating system for constructing secure, high-performance, reliable network applications across a variety of cloud computing and mobile platforms
- OpaOpa (programming language)Opa is an open source programming language for web applications.The language was first officially presented at the OWASP conference in 2010, and the source code was released onGitHubin June 2011, under a GNU Affero General Public License....
– an open source programming language for web development.
The private trading firm Jane Street Capital has adopted OCaml as its preferred language. http://cacm.acm.org/magazines/2011/11/138203-ocaml-for-the-masses/fulltext
See also
- CamlCamlCaml is a dialect of the ML programming language family, developed at INRIA and formerly at ENS....
and Caml Light, languages from which OCaml evolved - Standard MLStandard MLStandard ML is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of theorem provers.SML is a modern descendant of the ML...
, another popular dialect of ML - Extensible MLExtensible MLExtensible ML is an ML-like programming language that adds support for object-oriented idioms in a functional setting. EML extends ML-style datatypes and functions with a class construct designed to be extended into hierarchies, thus allowing the programmer to seamlessly integrate the...
, another object-oriented dialect of ML - O'Haskell, an object-oriented extension to the functional language HaskellHaskell (programming language)Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...
External links
- Caml language family official website
- OCaml tutorial for C, C++, Java and Perl programmers
- Jason Hickey book
- A basic OCaml tutorial
- A Tutorial with a practical approach.
- OCamlcore Planet aggregation of people and institutional feeds about OCaml.
- OCamlForge a free service to Open Source OCaml developers offering easy access to the best in source control management, mailing lists, bug tracking, message boards/forums, task management, site hosting, permanent file archival, full backups, and total web-based administration.
- OCaml Batteries Included, a community-built standard library for OCaml
- OCaml-Java, OCaml for Java
- OCamIL, an OCaml compiler for Microsoft .NET.NET FrameworkThe .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
- LablGL and LablGTK OpenGLOpenGLOpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...
+ bindings (LablGL) and GTK+GTK+GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...
bindings (LablGTK) - Newest OCaml Projects on Sourceforge
- Comparison of the speed of various languages including OCaml
- MetaOCaml home page
- the GODI package manager for OCaml
- Ocamlwizard