What does val mean in Ocaml

Viewed 1077

When seeing documentation of modules in Ocamel there is something like this for example in Graphics Module

val close_graph : unit -> unit

Or when writing a function in an interactive mode:

# let x () = 3;; 
val x : unit -> int = <fun>

there is val x : unit -> int = <fun>, What is val and it's use case?

1 Answers

Well, val is a keyword in OCaml with several different uses.

The cases you mention are both, in essence, that val is used in a module signature to specify values that appear in the module. Values are things like functions and expressions. (An example of something that's not a value that can appear in a module is a type.)

You can read about module signatures in Section 7.10 of the OCaml manual.

The first variant of the nonterminal specification is the one that begins with val.

(In the toplevel, you are creating a module as you type in your definitions. So the toplevel is using signature-style syntax to show what you've defined. So it seems to me anyway.)

Related