I had an understanding that, to use a constructor from an module A
that is not open
ed, I have to prefix it with the module name. However, I’ve noticed sometimes OCaml is clever enough to find the correct constructor from the unopened module, and can even select the correct one from candidates having the same name, so the following compiles:
module A = struct
type t = Foo | Bar
end
type a = Foo | Bar
type b = Foo | Bar
let f = function
| A.Foo -> A.Bar
| Bar -> Foo
let a : a = Bar
let b : b = Foo
It seems that this happens whenever OCaml already knows the type of the “hole” to be filled. Is this true? Is this lovely feature documented somewhere?