OCaml let expressions

I’ve been learning about let expressions in OCaml, which are not a complex concept but I’m definitely having trouble wrapping my head around them completely.

Instead of a standard let definition, e.g.

let x = 5

You can do something like this:

let x = 5 in x + 1

This in keyword basically functions like “in this scope”.

This means for with the second piece of code for example, if after this you decided to convert x into a string with something like:

string_of_int x

You would get an error like Error: Unbound value x.

This is because these let expressions only bind the value within a specified scope.

I’m trying to determine the exact use cases for these, and I imagine it’s for intermediate values where you want to name a value for clarity, and are using these values to compose some other value to be returned. But I’m still not entirely sure yet.