Re: Next YAML: drop equality definition
Oren Ben-Kiki <[email protected]> Fri, 4 Mar 2016 20:12:19 +0200
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <CADJiDhur=U-eRY=xBbvtnZqb4yY0i2ACKBqV9OgiwabDz7sfqg@mail.gmail.com> |
On Fri, Mar 4, 2016 at 7:49 PM, Osamu TAKEUCHI <[email protected]> wrote: > My question was: Can we evaluate mapping nodes' equality with > their identity instead of their property values? > If they are identical, they are equal. If they are not identical, they _may_ be equal. This question arose from your old post: > https://sourceforge.net/p/yaml/mailman/message/23576035/ >From this old post: "... it is Ok for a library to punt and pass the burden to the native data type implementation (which most YAML libraries do)...". The amount of effort a YAML processor puts into earlier detection of duplicates is entirely up to the implementation. It is considered well-behaved to make at least a cursory effort - in particular, complain about character-for-character identical scalar keys. Two mappings are equal only when they have the same tag and >> an equal set of keys, and each key in this set is associated >> with equal values in both mappings. >> > > It tells that the equality of mapping nodes must be done by > property values regardless of the equality operator of the > native object. It does not allow us to compare mapping nodes > by identity even if it is the native object's equality. > Ok, I finally get what you are getting at (sorry for being slow). The question is, what happens if operator== of the native data types is defined to compare _only_ the identity of the objects. In this case, the YAML processor would be wrong to do any form of early duplication detection. Good point. Note, this only applies to complex keys. The spec clearly says identity is not preserved for scalars. So the YAML processor _would_ be allowed to do early detection of _scalar_ keys. In fact it _should_ do so: if two scalar keys have the same content and same tag, they are equal. This is pretty simple and covers the cases we really care about (duplicate string keys). As for complex keys... On the one hand, using these sort of data type as a key - shudder. But, on the other hand, it is technically possible.... If we want to be able to serialize "everything", then you may have a good reason here that YAML processors must not compare complex keys for equality at all. Ugh. Nice catch... I wonder what Ingy and Clark think, but I think you may have killed early detection of equality for complex keys for equality. That should make implementations (and the spec) simpler. Oren. ------------------------------------------------------------------------------ _______________________________________________ Yaml-core mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/yaml-core