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

Heterogeneous Sets #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

LukeMathWalker
Copy link

No docs and tests could greatly be improved, but this is what I have done so far on HSets.

Copy link
Contributor

@jblondin jblondin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far!

Two thoughts:

  1. What makes this an ordered set? We don't have an ordering relation (and ordering heterogeneous lists sorta defies the concept)
  2. I haven't cloned and played with it yet, but what happens with union when the same label occurs in both sets?

lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
lhlist/src/ordered_set.rs Show resolved Hide resolved
lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
lhlist/src/ordered_set.rs Outdated Show resolved Hide resolved
@LukeMathWalker
Copy link
Author

LukeMathWalker commented Jul 1, 2019

1. I have named it OrderedHSet because the equality relationship I have in mind (yet to be implemented) is order-sensitive. Actually, the default implementation of Eq (the one we are deriving) should already do the job and it's order-sensitive.

2. Changing

ordered_set.union(singleton).union(another_set);

to

ordered_set.union(singleton).union(another_set.clone()).union(another_set);

fails at compile time with this charming error message:

error[E0271]: type mismatch resolving `<cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>> as relation::Member<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>>>::Output == relation::False`
  --> lhlist/src/ordered_set.rs:99:65
   |
99 |         ordered_set.union(singleton).union(another_set.clone()).union(another_set);
   |                                                                 ^^^^^ expected struct `relation::True`, found struct `relation::False`
   |
   = note: expected type `relation::True`
              found type `relation::False`
   = note: required because of the requirements on the impl of `ordered_set::OrderedHSet` for `cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>>`
   = note: required because of the requirements on the impl of `ordered_set::Union<cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>` for `cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>`
   = note: required because of the requirements on the impl of `ordered_set::Union<cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>` for `cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ShelfName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>`
   = note: required because of the requirements on the impl of `ordered_set::Union<cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>` for `cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ProductName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ShelfName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>>`
   = note: required because of the requirements on the impl of `ordered_set::Union<cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>` for `cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ProductId>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ProductName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ShelfName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>>>`
   = note: required because of the requirements on the impl of `ordered_set::Union<cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>` for `cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ShelfId>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ProductId>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ProductName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::ShelfName>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::Price>, cons::Cons<label::LabeledValue<ordered_set::tests::create_ordered_set::StoreName>, cons::Nil>>>>>>`

@jblondin
Copy link
Contributor

So, normally when I think of a union operation of two overlapping sets (where some labels exist in both sets), the union shouldn't fail but just return all the labels that exist. This becomes slightly more complicated with our requirements, as two things that are Labeled could actually be different but just have the same label (which is the only thing we're using for uniqueness within the set). Thus, the concept of union is a little poorly-defined except for label-only lists (with no attached data, i.e. LCons type). For label-only lists, at least, I would expect that union does not fail to compile, but gives the expected set union.

So, an OrderedHSet basically says it doesn't change the order of the items? Is this in the context of if you transformed a list (with potentially duplicate items) into an OrderedHSet? Or in the output of a union operation? If the latter, does this mean that the output set has all the items in the lhs set, followed by all the items in the rhs set that were not in the lhs?

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

Successfully merging this pull request may close these issues.

2 participants