The idea of labelled fields is to abstract away the relative order of those fields. You’re asking for something further(?) You want the user to not even know what other fields are in the datatype(?)
-
For H98-style ADTs, the supplier could export (some of) the field labels, but not the Constructor(s). So the user could at least select some values but not duplicate all of the original data type.
-
They could also use the labels to
updatebuild a new value from an old, withoverwriteablefresh-able values restricted to only those fields. -
But then the user couldn’t construct a whole fresh value of that type. (Because that would need access to the Constructor, (ab)using which could pattern-match on a value to grab all the fields the supplier was trying to hold abstract.)
-
?Supply a
PatternSynonym
as pseudo-constructor that exposes only some of the fields; but for a fresh value fills in defaults for the inaccessible fields?
For all the implementations of anonymous/extensible records I’m aware of, the situation is quite a bit worse:
-
Firstly, again the relative ordering of fields is held abstract/indeed the idea of field position doesn’t apply.
-
The field labels are
Symbol
(or equivalent), which are automatically global/the exporter can’t mention them inhiding
lists/they’re merely type-level names. -
And since the term-level name for the label is exactly the same as the type-level
Symbol
, the (ab)user can ‘guess’ the name to access the field just by looking at its type. “public duplicates of values” is easy. -
I suppose there could be a records system with separate term-level vs type-level labels, and with the term-level encrypted for what are supposed to be abstract fields ??? I’ve not seen/heard of that sort of bodging.
-
Supplier could make the type of the field content abstract; so a user could copy the value but not peek inside it(?)
-
A
PatSyn
defined over an anonymous record could kinda hide some labels – but “He’s behind you!” the (ab)user just looks at its type.