What does mean "open!"?

Hi !
At the beginning of Js_of_ocaml form.ml file, there is

open! Import

What does that mean ? (as there are no import.ml file, but js_of_ocaml__Import.cmi, .cmt and .cmx, I imagine it imports modules from those files, but I would like to understand)
Thanks !

The import file is here: https://github.com/ocsigen/js_of_ocaml/blob/master/lib/js_of_ocaml/import.ml. FWIW, I think the open! Import you’re referencing is here.

Just in case you’re also asking about the ! after open, open M brings all of the items in the module M into scope. The compiler will warn you if this open statement is unneeded, that is if you don’t use any of the items in M. However, using open! M instead will prevent this warning.

1 Like

Hmm, a small correction is needed here, open M warns if any of the items from M shadow any items that are already in scope. E.g.,

module M = struct let test = "" end

let test = ""

open M

let () = print_endline test

Warns:

Warning number 44
OCaml preview 5:1-6

this open statement shadows the value identifier test (which is later used)
1 Like

Ah shoot, that too — thanks!