-
Notifications
You must be signed in to change notification settings - Fork 62
pull 'Set'-producing operations | & ~ up to 'Collection' #7435
Comments
Oh and yes, you could then do |
I'm not necessarily disagreeing, but the performance characteristics are much more clear when written as |
Yeah, you'd probably want these operations to be lazy, especially for something like |
@jvasileff wrote:
Did you mean that they are unclear when written as @CPColin wrote:
You mean But yeah the |
Oops, you're right, my bad. |
You can do
Yep, the reason is that So what you're really asking for here is an operator for appending lists, something I've often wondered about adding. For So you would be able to write: I dunno, I've never been in love with the idea of using |
Oh, well, now, I remember, or course the problem here was that And nor could |
Interestingly, and subversively, nothing's stopping us from making |
Ah, excuse me, that's all rubbish, because the So I think it would indeed be possible to make That doesn't actually sound like terrible thing to do. |
Oh, I'm wrong again, the real problem is that |
So the only thing to do would be, I guess, to factor out That's a possible—and reasonable—thing to do. The only question is do we think it's a good idea to let people non-destructively join lists using |
What is the proper union of this expression: map{"key" -> "v1"} | map{"key" -> "v2"} |
@luolong oops, sorry, you're right, intersection can be defined for |
@gavinking wrote:
I understand that it is convenient that ranges can be expected to have a predictable order of elements, but aren't they also effectively
Could Anyway I would still miss the I'm closing this now but feel free to keep discussing. |
Well, sure, every |
One possible reasonable thing to do would be to define That would be a change with pretty minimal impact on the language, that makes the existing For example, |
@gavinking wrote:
Hmm, through using Java I have empirically developed the (perhaps incorrect) understanding that Your example with a sequence and a map is of course fine because all the elements of the set are unique. But based on my hypothesis above I would expect |
Well, I mean, mathematically, a set is a value with just one operation, ∊, which in Ceylon we write as In particular, (Note that the definition of set in mathematics doesn't say anything at all about iterating values, or any of the other things that distinguish
Right, |
The idea sounds really nice. So one would put default implementations in Collection and assumably override in (Reopening since there is now light again :) |
Set
-producing union, intersection etc operations to Collection
They could be overridden on |
I've implemented this idea (it was really straightforward) and it seems to be working well. I'll push it to a branch later. |
Set
-producing union, intersection etc operations to Collection
I've pushed my work to the 7435 branch. Now we need to see if there is really a consensus in favor of this. Feedback, please! |
I'm in favor of this. |
[ 1, 1 ] is indeed not considered to be a mathematical set, because a set is a collection of distinct objects. Therefore an iterable object may or may not be a set. If |
This isn't really correct, at least not in modern axiomatic set theory, where "set" is a primitive notion. The only operation a mathematical set has is ∊, and one can't distinguish |
Both of them are theories anyway, that's not what I really care about. The thing is, I believe having a collection that deals with distinct objects is very useful. Though if a |
There is no suggestion to change the semantics of |
Then it's more than ok. That would be very useful. |
Sorry I came a bit late to this discussion, but I think I should drop my five cents here. I don't think | & and ~ are actually part of the semantics for I.e. what's the meaning of the union of two Instead, I propose creating utility methods in collections, with similar meaning, that can be used to define
Those methods can serve as foundations for |
@someth2say The idea is that arbitrary collections can be trivially viewed as sets, because conceptually a set is just something that tells you whether or not it contains a given element. Taking the union of two lists means that you want to treat them as sets, you don't care about order, and you want to get back a set containing each distinct element that appears in either list. That's a useful thing to do.
The |
That's one of the root arguments I don't agree with. Quoting @gavinking: mathematically, a set is a value with just one operation, ∊. But practically, sets have many other characteristics we should not ignore (like all contained elements being unequal...and equality is really a hairy topic!).
That's another argument against pulling methods up. You should learn that, when you apply I'm proposing specific operations for all Also, as @jvasileff said, performance impact is much more clear when set transformation is explicit. |
Conceptually, we only care about ∊ with respect to the collection operands, but we care about more than just ∊ with respect to the result, which is why we return a
How is that a hidden transformation in some undesirable way that any other function isn't? In general, you don't know how any function is implemented, how it transforms its inputs. Why is that a problem here?
I could understand the objection if the time complexity jumped from linear to quadratic or something, but it's still linear, so what's the big deal? |
I was longing for
Set
operators/operations inRange
instances. Namelyunion
,intersection
but why not alsocomplement
andexclusiveUnion
.Sure, I can do
set(3..5).union(set(4..6))
, but is there any reason thatRange
couldn't satisfySet
? I read through #3557 and the current interfaces and their implementations and although I didn't perhaps catch everything, I felt I should ask.Since all operations except
intersection
may result in split ranges, the implied return value ofSet
is actually just fine. One could of course have a more specificRange<Element> intersectionWithRange(Range<Element> other)
for convenience.For these set operations one would naturally not care if the ranges are
increasing
ordecreasing
- the result would be the same i.e. the result would be normalized.As for an actual implementation it would perhaps be beneficial to override the default implementations from the
Set
interface for more efficient operation (as long as the "other" set is of same type as "this" set), but they would still be "just Sets"...Thanks for listening..
The text was updated successfully, but these errors were encountered: