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

ISequence naming #1

Closed
mlhaufe opened this issue Mar 9, 2022 · 4 comments
Closed

ISequence naming #1

mlhaufe opened this issue Mar 9, 2022 · 4 comments

Comments

@mlhaufe
Copy link

mlhaufe commented Mar 9, 2022

ISequence<T> implies an ordering which is not your intention I believe. Perhaps call it IStream<T>?

@cdiggins
Copy link
Owner

Ordering is a bit of an ambiguous term, I consider it ordered but not sorted. The ordering is determined by construction. If an item is added (appended), then it will always be returned as the last item. I'm using the term Sequence synonymously with Enumerable, but with the constraint that the first item is always the first item, and the last item is always the last item. Unfortunately with an IEnumerable is that it can change between invocations on the same data set.

The name is inspired by https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/sequences. I always found "enumerable" to be a bit of an obtuse academic term.

@mlhaufe
Copy link
Author

mlhaufe commented Mar 12, 2022

But if it's potentially infinite, how can you have an order beyond time? Can you have a concept of First or Last? I'm thinking of the example: ISequence<MouseClicks>

Is ISequence as a name compatible with the common formal usage? https://en.wikipedia.org/wiki/Sequence

@cdiggins
Copy link
Owner

In the Wikipedia article they do mention that a sequence can be infinite. Consider the sequence: "1,0,1,0,...". There is a first item, but indeed there is no last, which is the same problem as IEnumerable.

It is a good to note that any concept of infinite series, should be careful about introducing potentially undefined operations (like "ToArray()", "Last()", "TakeLastN()", "Reverse()"). I generally consider this a design mistake, but I decided to keep operation naming a 1-to-1 with LINQ, to facilitate cross-over.

Plato should be a drop-in replacement for any C# programmer, with a minimal learning curve. They just have to get used to pure functional programming.

Other inspirations for the name "Sequence" come from Scala (https://www.scala-lang.org/api/2.12.x/scala/collection/Seq.html), and was also used in Clojure (https://clojure.org/reference/sequences).

But if it's potentially infinite, how can you have an order beyond time?

You have the order in which it was add to the sequence during construction.

var xs = EmptySequence().Add(1).Add(5).Add(2); 
Console.WriteLine(xs.First()); // Always 1
Console.WriteLine(xs.ElementAt(1)); // Always 5
Console.WriteLine(xs.Last()); // Always 2

The idea of something being truly unordered is extremely rare in practice in programming. A Plato ISet is one example of this. You can ask whether something is in a set, you can create a set by combining or interesecting them. You can even take the true complement of a set (create the set of all things not in the set), which is not possible with IEnumerable. To make this possible, there has to be no operations that imply ordering. You simply cannot say "Get me the first item of a set". It makes no sense mathematically.

I also had a bag concept, but over the last week (and through our conversations) realized that it wasn't very useful practically, and I'll be removing it.

@mlhaufe
Copy link
Author

mlhaufe commented Mar 14, 2022

There's nothing wrong with a Bag (MultiSet). While the use cases are uncommon they are not rare I'd say.

I could represent the items in a Shopping Cart for instance. The order doesn't matter and I can have the same item multiple times. I also don't have to assume every item has a SKU number or some other common ID scheme.

@cdiggins cdiggins closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
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

2 participants