Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Write blog post about new tuples in Scala 3 #1186
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
Write blog post about new tuples in Scala 3 #1186
Changes from 4 commits
a3e1b86
23b2cab
52b6ec1
4d6abcf
38a678d
31ce557
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the word “dynamic” is so overloaded in programming as to be nearly meaningless in the absence of contextual information about what is intended. also in the context of a statically typed language, “dynamic” can be a negative word, not necessarily a positive one!
not sure what rewording to suggest, needs a little thinking about what you're really trying to get across here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also “new range of operations” is a bit peculiar/unidiomatic. “wider range of operations” would sound right. simply "new operations” would also sound right. not sure which meaning you intend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels a bit odd to me to lead with material about Python. Not everybody even knows Python (I don't) or knows what concept of tuple it has (I'm vaguely aware it's different from Scala's, but couldn't tell you how).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with Python because it is the only main stream language providing tuples. I could have started with Rust or Haskell but probably they are less well known
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It's not so much the choice of Python specifically I'm reacting to, but the choice to lead with a comparison to any other programming language at all. Anyway, no big deal.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will
_1
etc be deprecated in the future? if not, why not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit uncomfortable with this example because it seems like something one shouldn't do. What is the purpose of allowing indexed access like this? Is the main purpose consistency? Or is the main purpose that we actually expect such looping-over-a-tuple to be common? I doubt it will be common, and so using it too prominently in an example runs the risk of confusing readers about what tuples are for.
If iterating over a tuple is uncommon but something one might occasionally want to do, then I think it would be good to clearly signal that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the "eventually" here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this sentence. We could already program with tuples and manipulate them before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to say that in Scala 2 tuples are static: we cannot add terms, we cannot drop terms, it is hard to iterate over them etc... while in Scala 3 they are more similar to collections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the birth of Scala, we've been emphasizing to people learning the language that lists and tuples are completely different things used for completely fferent purposes. Now it seems like the story has changed and they're becoming more interchangeable, more overlapping in purpose. Why, and under what circumstances, is that even good?, is the main thing I feel is missing from this blog post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t have this feeling. I have seen multiple blog articles, talks, or libraries about
HList
s (which is what Scala 3 tuples really are), and I think their usage is quite common in type-level programming. But I agree that we should explain that better in the motivation part of this blog article.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the difference that application authors won't normally need to manipulate tuples in these new ways, but library authors might?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's probably more common to library authors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I
.drop(n)
or can I only use a literal integer?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so you can do it, but instead of getting an ordinary tuple, I get something called a
Tuple.Drop
— what is that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tuple.Drop <: Tuple
is a match type describing the result of the drop operation. This is the pattern that I show in the second part of the post, reimplementing++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/lampepfl/dotty/blob/f57055cfb60682bf34858bd06b7e65d97a77399c/library/src/scala/Tuple.scala#L180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean "we must choose the type of the resulting collection", or do you mean something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that we must be careful when we choose the conversion because we can have mutable or immutable containers (
Array
vsIArray
) but we also have different behaviors in the element type (return ofPolyFunction
,Object
or union type)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be a link here to something that would explain to me what a PolyFunction is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to find a nice explanation in the docs. Did you have a specific resource in mind ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At https://dotty.epfl.ch/docs/reference/overview.html it says:
and then it just links to scala/scala3#4672 rather than to a proper documentation page
So it seems the documentation is out of date. I don't actually know what the current status of the feature is, actually — I guess you'd have to ask someone on the Dotty team.