I'm looking for a search tree implementation in Haskell which provides an efficient difference function for trees which share structure. For example, if I have a large tree `x` (e.g. with millions of elements) and I insert three new elements into it to produce `x'`, I'd like to be able to invoke `difference x x'` to get those elements back, where `difference` is implemented such that the elements of interest are found by only visiting the nodes not shared between the two trees.

The scenario I have in mind is like that of a version control system, where each new version is derived from the previous one, and we may need to find the difference between any two versions.

The data structure should support efficient insertion, deletion, and lookup operations (e.g. O(log n)) as well.

Such an implementation would rely on something like System.Mem.StableName or Data.Unique.Id to label each node in the tree uniquely, allowing the `difference` function to efficiently recognize shared structure and avoid descending into it.

Does something like this exist already? If not, what's a good strategy for implementing it? I was thinking of modifying something like Wu Xingbo's RBTree implementation to add unique labels to each node, but I'm open to other options.