Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a decison on order preserving key value collection #1

Open
ratmice opened this issue May 14, 2022 · 0 comments
Open

Make a decison on order preserving key value collection #1

ratmice opened this issue May 14, 2022 · 0 comments

Comments

@ratmice
Copy link
Owner

ratmice commented May 14, 2022

Background

Crimson has a dichotomy between ordered and unordered collections,

  • Set: {0, 1, 2}
  • Array: [0, 1, 2]
  • Map: {"foo" = 1, "bar" = 2}

For syntactic consistency it somewhat makes sense to include

  • Tree: ["foo" = 1, "bar" = 2]

This rule is commented out of the grammar here:

crimson/src/crimson.y

Lines 60 to 69 in a0472b0

// The equivalent of an Ordered key value data structure would be some bare form of a tree
// Acting like an array of tuples, It is probably best to just encode this explicitly as a array of tuples,
// or explicitly as a struct.
//
// Essentially it would allow you to write:
// [(1, "foo"), (0, "bar")]
// as [1 = "foo", 0 = "bar"]
//
// I don't really see any motiviation for including it though...
// | '[' KvSeq ']'

Argument for

I think that the biggest argument for allowing it comes from the order_preserving feature of the following libraries:
https://docs.rs/crate/toml/latest/features
https://docs.rs/crate/serde_json/latest/features

These existence of these features here wouldn't actually help much for converting between json or toml and crimson ordered/order preserving types depending upon whether this flag is enabled.
But I think the problems associated with these features, and even their mere existence at least provides some motivation
for having an ordered preserving tree.

Argument against

It is kind of weird, and no other serialization languages I know of include any kind of order preserving tree.
Of those languages that don't include it, I know of zero complaints regarding it, If you need order preserving you probably just use an order preserving parser if not you don't.

This would make crimson -> json a non-injective surjective function where Tree and Map both correspond to json's Object,
however I believe that is already the case regarding Set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant