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

Switch to ? for wildcard types #7144

Merged
merged 3 commits into from Sep 11, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 30, 2019

Refactor dotty codebase so that we now use ? instead of _ for wildcard types

The old `for T` syntax cfor given impiorts is no longer valid
Backends are left out for the moment. Everything else now uses `?`.
@julienrf
Copy link
Collaborator

julienrf commented Aug 31, 2019

I don’t remember if that has been discussed somewhere, but should we use ? as well for the wildcard pattern, for symmetry?

x match {
  case Foo("bar", ?) => ...
  case q: Quux[?] => ...
}

Edit: I see that a similar idea was proposed in lampepfl/dotty-feature-requests#49

@odersky
Copy link
Contributor Author

odersky commented Sep 3, 2019

@julienrf

should we use ? as well for the wildcard pattern, for symmetry?

That's a good question. We have two uses of _, depending on location:

  • in expressions or types (i.e. things that are produced), an underscore will be a placeholder for a missing parameter.
  • in patterns or bindings (i.e. things that are consumed), an underscore represents an ignored parameter.

You can say in both places an underscore represents an unnamed parameter, but that meaning changes between producers and consumers.

Pattern cases are fundamentally lambdas, so using an underscore meaning "ignored" is natural. I was on the fence for a while what to do about type patterns. E.g

case xs: List[t] => xs.head: t

The case is logically a type lambda over t followed by a term lambda over List[t]. By that analogy, we should keep _ for ignored parts of type patterns. But then we would run into an ambiguity for parts of higher-kinded types, like this one:

case x: EitherT[List[_], A, B] => 

@liufengyun
Copy link
Contributor

A purely subjective comment: when I see a question mark, I feel something is wrong and there is something to be done.

@odersky odersky merged commit d7896b5 into scala:master Sep 11, 2019
@odersky odersky deleted the refactor-wildcard branch September 11, 2019 10:25
@anatoliykmetyuk anatoliykmetyuk added this to the 0.19 Tech Preview milestone Sep 19, 2019
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.

None yet

5 participants