You can open A locally:
let f (x : foo) = A.(match x with
| Bar m -> Bar (g m)
| Baz | Boo -> x)
or
let f (x : foo) =
let open A in
match x with
| Bar m -> Bar (g m)
| Baz | Boo -> x)
You can define Bar
in a submodule so that less things are exposed:
module A = struct
module BasicDataAndOps = struct
type foo = Bar of material | Baz | Boo
end
open BasicDataAndOps
(* other stuff *)
end
module B = struct
open A.BasicDataAndOps
...
For use outside of patterns, you can define a "smart constructor" in B:
let bar m = A.Bar m
ETA: I forgot about the possibility to restate type definition, described in Ashish Argwal's answer: type foo = A.foo = Bar of material | Baz | Boo
. Given that you already have type abbreviation in your example, this is the best answer.
There is some work on type-based label disambiguation which could be helpful, but it may not get accepted into the language.