Hi, I wanted to share this small experiment about using Backpack module signatures to manage encapsulation “levels” for abstract datatypes.
The basic motivation is the following: we often want abstract datatypes which hide their internals from the prying eyes of other modules. But we also want to be able to inspect the internal structure of values for logging or debugging purposes. How to reconcile the two aims?
In my experiment, the program logic depends on a module signature which defines a
Mystery type constructor with very few operations. The “inspection” function for datatypes returns
Strings wrapped in this
Mystery constructor. Other functions in the program logic can’t do anything with these wrapped values.
However, “framework” -like code gives a concrete implementation to the
Mystery type constructor, meaning that it can can do useful things with the result of “inspection” functions.
I’m left with a question: can something similar to this be achieved without Backpack?