Measures Concepts
GitHub icon

OCaml

OCaml - Programming language

< >

OCaml is an open source programming language created in 1996 by Xavier Leroy.

#71on PLDB 28Years Old 27kRepos

Try now: Riju · TIO

OCaml ( oh-KAM-əl), originally named Objective Caml, is the main implementation of the programming language Caml, created by Xavier Leroy, Jérôme Vouillon, Damien Doligez, Didier Rémy, Ascánder Suárez and others in 1996. A member of the ML language family, OCaml extends the core Caml language with object-oriented programming constructs. OCaml's toolset includes an interactive top-level interpreter, a bytecode compiler, a reversible debugger, a package manager (OPAM), and an optimizing native code compiler. Read more on Wikipedia...


Example from Compiler Explorer:
let square x = x * x
Example from Riju:
;; print_string "Hello, world!\n"
Example from hello-world:
print_string "Hello World\n"
(* Hello World in OCaml *) print_string "Hello World!\n";;
Example from Linguist:
(* * Copyright (c) 2013 Jeremy Yallop. * * This file is distributed under the terms of the MIT License. * See the file LICENSE for details. *) let string_of format v = let buf = Buffer.create 100 in let fmt = Format.formatter_of_buffer buf in begin format fmt v; Format.pp_print_flush fmt (); Buffer.contents buf end
Example from Wikipedia:
fun x_1 -> (x_1 * let y_3 = let y_2 = (x_1 * 1) in (y_2 * y_2) in (y_3 * y_3))
OCaml Keywords
as assert begin class constraint do done downto else end exception external false for fun function functor if in include inherit initializer lazy let match method module mutable new object of open private raise rec sig struct then to true try type value val virtual when while with

Language features

Feature Supported Token Example
Binary Literals ✓
Integers ✓
Floats ✓
Hexadecimals ✓
Octals ✓
Conditionals ✓
Functions ✓
Classes ✓
While Loops ✓
Booleans ✓ true false
Print() Debugging ✓ print_string
MultiLine Comments ✓ (* *)
(* A comment
*)
Module Pattern ✓
(* In OCaml, every piece of code is wrapped into a module. *)
(* amodule.ml *)
let hello () = print_endline "Hello"
(* bmodule.ml *)
Amodule.hello ()
Type Inference ✓
Multiple Inheritance ✓
Comments ✓
(* This is a single-line comment. *)
(* This is a
 * multi-line
 * comment.
 *)
Case Insensitive Identifiers X
Semantic Indentation X
Line Comments X

View source

- Build the next great programming language · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Day 605 · feedback@pldb.io · Logout