I am currently working on a "plugable", augmented run-time type system for Javascript to facilitate type-directed functional programming in untyped environments. It is essentially based on Proxy
virtualization. Proxies are great, though they are not always transparent:
const xs = [1,2,3];
const xs_ = new Proxy(xs, {});
const s = new WeakSet([xs]);
s.has(xs); // true
s.has(xs_); // false
The same object may appear with and without a Proxy
contract during run-time. Since Javascript defines object identity by reference, proxies are opaque when it comes to comparison of objects with their contracted counterparts.
As a result I'd lose WeakMap
/WeakSet
and the ===
operator, when working with proxies along with object types. Apart from that I would have to compare their properties recursively, which may be a rather expensive operation.
Is there a straightforward workaround in vanilla Javascript to keep proxies transparent?
Since I guess the answer to my question is no, here is an additional, more general one:
With purely functional languages the identity of data structures seem to be defined by state rather than by reference. While I know that deep cloning doesn't matter much in the presence of persistent data structures / structural sharing, recursive value comparison seems to be as expensive as with ordinary Javascript.
How do purely functional languages reduce the complexity of extensive data structure comparison?