Variable Declaration
Browse / OCaml Cheat Sheet
OCaml Cheat Sheet
A concise reference for OCaml syntax, data structures, and common functions. Perfect for quick lookups and reminders.
Basics & Syntax
Basic Syntax
|
|
|
|
Function Definition |
|
|
Function Application |
|
|
Semicolon Usage |
|
|
Comments |
|
|
If-Then-Else |
|
Basic Data Types
|
Integer |
|
|
Float |
|
|
Boolean |
|
|
Character |
|
|
String |
|
|
Unit |
|
Operators
|
Arithmetic (int) |
|
|
Arithmetic (float) |
|
|
Comparison |
|
|
Logical |
|
|
String Concatenation |
|
Data Structures
Tuples
|
Definition |
|
|
Accessing Elements |
|
|
Type |
|
Lists
|
Definition |
|
|
Cons Operator |
|
|
Head and Tail |
|
|
Common Functions |
|
|
Type |
|
Arrays
|
Definition |
|
|
Accessing Elements |
|
|
Modifying Elements |
|
|
Type |
|
Records
|
Definition |
|
|
Accessing Fields |
|
|
Modifying Fields (using |
|
Variants
|
Definition |
|
|
Parameterized Variants |
|
|
Recursive Variants |
|
Functions & Modules
Function Basics
|
Anonymous Functions |
|
|
Currying |
All functions in OCaml are curried by default. |
|
Recursive Functions |
|
Higher-Order Functions
|
Map |
|
|
Filter |
|
|
Fold Left |
|
|
Fold Right |
|
Modules
|
Module Definition |
|
|
Module Usage |
|
|
Module Types (Interfaces) |
|
|
Module Implementation |
|
Functors
|
Functor Definition |
|
|
Functor Application |
|
Advanced Features
Pattern Matching
|
Basic Matching |
|
|
Matching with Guards |
|
|
Matching on Tuples |
|
Exceptions
|
Defining Exceptions |
|
|
Raising Exceptions |
|
|
Handling Exceptions |
|
References
|
Creating References |
|
|
Accessing Reference Value |
|
|
Modifying Reference Value |
|
Objects
|
Basic Object Definition |
|
|
Creating an Object |
|
|
Using Object Methods |
|