There are many good OCaml tutorials on line from diverse usage patterns. Here is another. This should perhaps come first, especially if this page seems difficult.

The primary way to assign a value to a variable v and then use that value is:
let v = log 2. in v *. v If you type that into the REPL and add “;;” and a return, you see:

# let v = log 2. in v *. v;;
- : float = 0.480453013918201388
There are two advantages over (log 2.) *. (log 2.);; it is generally shorter, and the log computation is not repeated. If you ask the value of v afterwards; v;; it has forgotten the variable and its value. let r = 42;; in the repl causes the top level name space to remember r and its value until another such action gives r a new type and value.

It is common to cascade these as in

let a = 4 and b = 9 in let z = a + b in z * z;;
which gets you 169. Another pattern results from using this construct as an expression with a value as in sqrt (let v = log 2. in v *. v).

The context of the first v, after the let is called a pattern. Other things can go there too. let (a, b) = (4, 5) in a + b;; gets you 9. The (4, 5) is called a tuple, or actually an n-tuple where n is 2. The pattern on the left is matched with what must turn out to be a tuple value. OCaml has tuples which need not be homogeneous, and lists and arrays which must be. Here is an inhomogeneous triple

# (4, 5.3, "string");;
- : int * float * string = (4, 5.3, "string")
OCaml worries a great deal about types and you can see here how it thinks about them. [3; 4; 5] is a list of integers and [|3; 4; 5|] is an array.

Of course these can be used together.

([3; 4; 6], [|4; 6|]);;
is welcomed by the REPL, but [3; 4; 6.] is rejected because the type of “6.” is not an integer and lists must be homogeneous.
let [a; t] = [4; 6] in a+t;;
adds 4 to 6 but worries that the list delivered by the right side may not be just two long. The REPL complains at ‘compile time’ but supposes that you might have done the right thing which turns out to be true.
# let [a; t] = [4; 6; 8] in a+t;;
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
[]
Exception: Match_failure ("", 150, -269).
The above is bad program illustrating what the compile time feared. The exception was discovered as the program ran.