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

Add/collection strawman #1160

Merged
merged 4 commits into from
Mar 18, 2016
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 9, 2016

Two additiions:

  1. A new strawman centered around views rather than iterators
  2. An improvement to overloading resolution which lets us use the Scala 2.8 calling
    idioms for map on String. Previously, this required an explicit type annotation.

}

/** Iterator defined in terms of indexing a range */
trait RandomAccessView[+A] extends View[A] {
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK Rust initially had RandomAccessIterator, but then they decided to drop it. It was creating more problems than solving.

It worked more or less by accident before. Now it's more complicated,
but we also have tests.
@lrytz
Copy link
Member

lrytz commented Mar 10, 2016

Looked a bit more through the strawman

  • Could Iterator and View be unified?
  • What's the intended use for IterableOnce?

@DarkDimius
Copy link
Contributor

Could Iterator and View be unified?

The only diffence between view and iterator lies in fact that views can be traversed several times.
In my variation of the original strawman, I was proposing to make this change:

class View[A](val v: ()=> Iterator[A]) extends AnyVal

Ie: view is just a producer of iterators

@lrytz
Copy link
Member

lrytz commented Mar 10, 2016

Ah, thanks - so the by-name here is crucial:

object View {
  def fromIterator[A](it: => Iterator[A]): View[A] = new View[A] { def iterator = it }
}

odersky added a commit that referenced this pull request Mar 18, 2016
@odersky odersky merged commit bd8a6dc into scala:master Mar 18, 2016
Copy link
Contributor

@adriaanm adriaanm left a comment

Choose a reason for hiding this comment

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

Implementing this in 2.12.0-RC1 broke existing code: https://issues.scala-lang.org/browse/SI-9943. It had a pretty weird overload where one parameter list was implicit and the other wasn't. We could ad-hoc exclude those cases, as the programmer probably doesn't think of them as overloaded, but that seems pretty, well, ad-hoc.

@odersky
Copy link
Contributor Author

odersky commented Oct 3, 2016

Alternatively, demand that all parameter types are the same. That's what dotty does currently. It compiles the code in SI-9943 OK.

@adriaanm
Copy link
Contributor

adriaanm commented Oct 3, 2016

Yep, this is the main aspect where Scala 2's implementation differs. It seemed more regular to me to just lub the argument types, but maybe we need to be more strict, based on this bug report.

@adriaanm
Copy link
Contributor

adriaanm commented Oct 4, 2016

Interestingly, this turned out to be a different problem: we admitted sealed classes (like <:<) as SAM types. Closing that hole made the type checker happy.

@allanrenucci allanrenucci deleted the add/collection-strawman branch December 14, 2017 16:57
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.

4 participants