Skip to content

Decide on the syntax of given in patterns #10087

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

Closed
smarter opened this issue Oct 26, 2020 · 1 comment
Closed

Decide on the syntax of given in patterns #10087

smarter opened this issue Oct 26, 2020 · 1 comment
Assignees
Milestone

Comments

@smarter
Copy link
Member

smarter commented Oct 26, 2020

Currently the syntax for given in patterns looks like:

  def f1[T](x: Ordering[T]) = (x, x) match {
    case (given y: Ordering[T], _) => new TreeSet[T]
  }
  def f4[T](x: Ordering[T]) = {
    val xs = List(x, x, x)
    for given _: Ordering[T] <- xs
    yield new TreeSet[T]
  }

Which is different from the expression syntax where we write given Type or given name as Type, aligning ourselves would be nice, although the as syntax isn't so useful since we can use pattern bindings name @ given Type or name as given Type after #9837, so we could support only the given Type syntax.

@odersky
Copy link
Contributor

odersky commented Oct 26, 2020

In the Dotty meeting the consensus was to keep only the anonymous given Type syntax. If a name is desired, it can be added with a as binder as in other patterns. I.e. the example would be

def f1[T](x: Ordering[T]) = (x, x) match {
    case (given Ordering[T], _) => new TreeSet[T]
  }
  def f4[T](x: Ordering[T]) = {
    val xs = List(x, x, x)
    for given Ordering[T] <- xs
    yield new TreeSet[T]
    for x as given Ordering[T] <- xs
    yield new TreeSet[T]
  }

odersky added a commit to dotty-staging/dotty that referenced this issue Oct 26, 2020
See the reference doc pages in this commit for details
odersky added a commit to dotty-staging/dotty that referenced this issue Oct 26, 2020
See the reference doc pages in this commit for details
bishabosha added a commit that referenced this issue Oct 30, 2020
Fix #10087 : Change syntax of given instances in patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants