-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Context Bounds for Polymorphic Functions #21643
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 18 commits
a76470f
8dc68c3
3ac5cec
408aa74
134c015
309034e
64bd03e
5196efd
5f0d4a7
a736592
0af8397
9c66069
ec6d7ef
dfa9240
7755e3b
24e3fa0
f292ac5
f9db9fa
952eff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3429,7 +3429,7 @@ object Parsers { | |
* | ||
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’ | ||
* TypTypeParam ::= {Annotation} | ||
* (id | ‘_’) [HkTypeParamClause] TypeBounds | ||
* (id | ‘_’) [HkTypeParamClause] TypeAndCtxBounds | ||
* | ||
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’ | ||
* HkTypeParam ::= {Annotation} [‘+’ | ‘-’] | ||
|
@@ -3460,7 +3460,9 @@ object Parsers { | |
else ident().toTypeName | ||
val hkparams = typeParamClauseOpt(ParamOwner.Hk) | ||
val bounds = | ||
if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) else typeBounds() | ||
if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) | ||
else if in.featureEnabled(Feature.modularity) && paramOwner == ParamOwner.Type then typeAndCtxBounds(name) | ||
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. why does this need the modularity import? isn't it part of SIP-64 so should be enabled without a feature? 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. Hmmm, I assumed that, since it was meant to be pushed to the next minor, it should be under a language import. 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, we should fix that in the followup and backport to RC2. 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. |
||
else typeBounds() | ||
TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
trait Ord[X]: | ||
def compare(x: X, y: X): Int | ||
type T | ||
|
||
trait Show[X]: | ||
def show(x: X): String | ||
|
||
val less0: [X: Ord] => (X, X) => Boolean = ??? | ||
|
||
val less1 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
type PolyTest1 = [X] => X => Ord[X] ?=> Boolean | ||
|
||
val less1_type_test: [X: Ord] => (X, X) => Boolean = | ||
[X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less2 = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
|
||
val less2_type_test: [X: Ord as ord] => (X, X) => Boolean = | ||
[X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
|
||
type CtxFunctionRef = Ord[Int] ?=> Boolean | ||
type ComparerRef = [X] => (x: X, y: X) => Ord[X] ?=> Boolean | ||
type Comparer = [X: Ord] => (x: X, y: X) => Boolean | ||
val less3: Comparer = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
|
||
type CmpRest[X] = X => Boolean | ||
type CmpMid[X] = X => CmpRest[X] | ||
type Cmp3 = [X: Ord] => X => CmpMid[X] | ||
val lessCmp3: Cmp3 = [X: Ord] => (x: X) => (y: X) => (z: X) => summon[Ord[X]].compare(x, y) < 0 | ||
val lessCmp3_1: Cmp3 = [X: Ord as ord] => (x: X) => (y: X) => (z: X) => ord.compare(x, y) < 0 | ||
|
||
// type Cmp[X] = (x: X, y: X) => Boolean | ||
// type Comparer2 = [X: Ord] => Cmp[X] | ||
// val less4: Comparer2 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
type CmpWeak[X] = X => Boolean | ||
type Comparer2Weak = [X: Ord] => X => CmpWeak[X] | ||
val less4_0: [X: Ord] => X => X => Boolean = | ||
[X: Ord] => (x: X) => (y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
val less4_1: Comparer2Weak = | ||
[X: Ord] => (x: X) => (y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less5 = [X: [X] =>> Ord[X]] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less5_type_test: [X: [X] =>> Ord[X]] => (X, X) => Boolean = | ||
[X: [X] =>> Ord[X]] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less6 = [X: {Ord, Show}] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less6_type_test: [X: {Ord, Show}] => (X, X) => Boolean = | ||
[X: {Ord, Show}] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less7 = [X: {Ord as ord, Show}] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
|
||
val less7_type_test: [X: {Ord as ord, Show}] => (X, X) => Boolean = | ||
[X: {Ord as ord, Show}] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
|
||
val less8 = [X: {Ord, Show as show}] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less8_type_test: [X: {Ord, Show as show}] => (X, X) => Boolean = | ||
[X: {Ord, Show as show}] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0 | ||
|
||
val less9 = [X: {Ord as ord, Show as show}] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
KacperFKorban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
val less9_type_test: [X: {Ord as ord, Show as show}] => (X, X) => Boolean = | ||
[X: {Ord as ord, Show as show}] => (x: X, y: X) => ord.compare(x, y) < 0 | ||
|
||
type CmpNested = [X: Ord] => X => [Y: Ord] => Y => Boolean | ||
val less10: CmpNested = [X: Ord] => (x: X) => [Y: Ord] => (y: Y) => true | ||
val less10Explicit: CmpNested = [X] => (x: X) => (ordx: Ord[X]) ?=> [Y] => (y: Y) => (ordy: Ord[Y]) ?=> true | ||
|
||
type CmpAlias[X] = X => Boolean | ||
type CmpNestedAliased = [X: Ord] => X => [Y] => Y => CmpAlias[Y] | ||
|
||
val less11: CmpNestedAliased = [X: Ord] => (x: X) => [Y] => (y: Y) => (y1: Y) => true | ||
val less11Explicit: CmpNestedAliased = [X] => (x: X) => (ordx: Ord[X]) ?=> [Y] => (y: Y) => (y1: Y) => true | ||
|
||
val notationalExample: [X: Ord] => X => [Y: Ord] => Y => Int = | ||
[X] => (x: X) => (ordx: Ord[X]) ?=> [Y] => (y: Y) => (ordy: Ord[Y]) ?=> 1 | ||
|
||
val namedConstraintRef = [X: {Ord as ord}] => (x: ord.T) => x | ||
type DependentCmp = [X: {Ord as ord}] => ord.T => Boolean | ||
type DependentCmp1 = [X: {Ord as ord}] => (ord.T, Int) => ord.T => Boolean | ||
val dependentCmp: DependentCmp = [X: {Ord as ord}] => (x: ord.T) => true | ||
val dependentCmp_1: [X: {Ord as ord}] => ord.T => Boolean = [X: {Ord as ord}] => (x: ord.T) => true | ||
|
||
val dependentCmp1: DependentCmp1 = [X: {Ord as ord}] => (x: ord.T, y: Int) => (z: ord.T) => true | ||
val dependentCmp1_1: [X: {Ord as ord}] => (ord.T, Int) => ord.T => Boolean = | ||
[X: {Ord as ord}] => (x: ord.T, y: Int) => (z: ord.T) => true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
42 | ||
a string | ||
Kate is 27 years old | ||
42 and a string | ||
a string and Kate is 27 years old | ||
Kate is 27 years old and 42 |
Uh oh!
There was an error while loading. Please reload this page.