Description #
OCaml (Objective Caml) is a general-purpose functional programming language with strong type inference, pattern matching, and support for imperative and object-oriented paradigms. It’s known for being expressive, fast, and safe — popular in academia, compiler design, and industrial applications like formal verification and finance.
History #
OCaml originated from Caml, developed in the 1980s at INRIA, the French national research institute. OCaml (Objective Caml) was released in 1996 as an extension with full support for object-oriented programming.
Key milestones:
- Developed and maintained by the Gallium team at INRIA
- A major influence on newer languages like F#, ReasonML, and Rust
- Widely used in formal verification, such as in the Coq proof assistant
- The Jane Street trading firm uses OCaml for critical financial infrastructure
Hello World Code #
print_endline "Hello, World!";;
How to Run #
Online: #
- Visit https://try.ocamlpro.com
- Paste the code and click Evaluate
Locally: #
- Install OCaml with OPAM (the package manager):
brew install ocaml # on macOS
sudo apt install ocaml # on Debian/Ubuntu
Save the code in hello.ml
Run:
ocaml hello.ml
Key Concepts #
print_endline
— outputs a string with a newline- Type inference — types are checked but rarely written
- Immutability — values are immutable by default
- Pattern matching — expressive control flow
- Modules and functors — modular architecture
- Garbage collection — automatic memory management
- Functional core — pure functions, recursion, no side effects
- Interoperable — can call C functions and compile to native code
- REPL support — interactive top-level (REPL) for quick testing
- Compiles to bytecode or native — flexible performance options
Try It Online #
🔗 Try OCaml
🔗 Replit – OCaml
🔗 OCaml.org Playground
Fun Facts #
- The “O” in OCaml stands for “Objective”, due to its OO support
- OCaml is behind financial systems processing billions in trades daily
- The Coq formal proof assistant is written in OCaml
- Facebook’s ReasonML and ReScript stem from OCaml
- Used to teach CS theory in many European universities