-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #10087 : Change syntax of given instances in patterns #10091
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
Changes from 4 commits
2ea9761
eeb02ca
18cdb7c
746cff7
718dacd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+4 −4 | modules/deriving/src/test/scala/shapeless3/deriving/type-classes.scala |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ class Test { | |
import scala.collection.immutable.{TreeSet, HashSet} | ||
|
||
def f2[T](x: Ordering[T]) = { | ||
val (given y: Ordering[T]) = x | ||
val (given Ordering[T]) = x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. This allows for a given to be bound to a val (y as given Ordering[T]) = x There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand this correctly, the y is not implicit here (hence the error on next line), and the given Ordering is not visible outside of the pattern its part of, so while this syntax is permitted because any pattern can be used in a val, it's useless. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smarter: correct. implicits in patterns behave the same way. |
||
new TreeSet[T] // error: no implicit ordering defined for T | ||
} | ||
def f3[T](x: Ordering[T]) = { | ||
val given y: Ordering[T] = x // error: pattern expected | ||
val given Ordering[T] = x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this one work as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it should work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we should have some tests |
||
new TreeSet[T] // error: no implicit ordering defined for T | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import math.Ordering | ||
import collection.immutable.TreeSet | ||
|
||
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] | ||
} |
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.
How would we re-write the following pattern to make
x
,y
andz
givens?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.
We should have tests with nested given patterns.
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.
you can't make
x
a given here. forx
andy
it would simply be:We already have a test like this.
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.
This seems to be a core limitation of the syntax.
The given statement syntax is
What if we used the same in patterns?
Then we could extend it to