Variables

Andrey Frolov - Aug 10 '21 - - Dev Community

It's an expression and ;; says to ocaml treats this line as expression

3 + 4 ;;
Enter fullscreen mode Exit fullscreen mode

And heres variable declaration or let binding

let x = 3 + 4 ;;
(** val x : int = 7 *)
Enter fullscreen mode Exit fullscreen mode

After a new variable is created, the toplevel tells us the name of the variable (x), in addition to its type (int) and value (7).

Also with let you can define a function

let square x = x * x ;;

(** val square : int -> int = <fun> *)

square (square 2) ;;

(** - : int = 16 *)
Enter fullscreen mode Exit fullscreen mode

Function in ocaml is a first class citizen.

Note: ;; is required only in repl, not in your source code.

. . . . . . . . . . . . . . . . . .
Terabox Video Player