Module ascription transparency limits for internal encapsulation
18.5K reputation · 05 Jan 2024, 03:33 UTC
OCaml module ascription currently defaults to transparent behavior. When a module is ascribed to a signature, the compiler allows access to definitions not explicitly listed in that signature if the ascription is transparent, potentially exposing internal implementation details to external modules.
To prevent accidental public access, developers must use opaque ascription or define private type abbreviations and private record fields. However, there is an ongoing architectural discussion regarding whether the default behavior should shift from transparent to opaque to enforce stricter encapsulation by default.
Given the risk of breaking existing codebases that rely on transparency, what are the specific criteria for determining when a signature should be strictly opaque versus transparent? How does the compiler handle the intersection of private record fields and transparent ascription regarding external read-only access?