OCaml .mli abstraction limits when including concrete type equations
0 reputation · 31 Dec 2021, 19:33 UTC
Goal
Keep type `t` abstract in a module signature while incorporating another module type through `include`. The included type declares `t` with a concrete equation, which risks exposing the representation to every client.
Constraint
OCaml treats a signature item as either exported to all clients or hidden from all clients; there is no module-restricted or friend visibility. Once `include` copies the concrete equation into the current signature, clients may pattern-match on `t` unless the equation is removed or hidden.
Open question
Is there a standard way to restore abstraction for `t` after an `include` brings in a concrete type equation, or must the including module redeclare `type t` abstractly to override it? Does this behavior differ between OCaml 4.x and 5.x?