Skip to content

Commit 94562bf

Browse files
committed
Change syntax to instance-of-given.
Also, handle superclass arguments with given arguments.
1 parent f572f7a commit 94562bf

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

docs/docs/internals/syntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’
385385
ConstrApps ::= ConstrApp {‘with’ ConstrApp}
386386
| ConstrApp {‘,’ ConstrApp}
387387
ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args)
388+
| ‘(’ ConstrApp {‘given’ (InfixExpr | ParArgumentExprs)} ‘)’
388389
ConstrExpr ::= SelfInvocation
389390
| ConstrBlock
390391
SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}

docs/docs/reference/contextual-instance/derivation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ calling the `error` method defined in `scala.compiletime`.
314314
**Example:** Here is a slightly polished and compacted version of the code that's generated by inline expansion for the derived `Eql` instance of class `Tree`.
315315

316316
```scala
317-
instance [T] given (elemEq: Eql[T]) of Eql[Tree[T]] {
317+
instance [T] of Eql[Tree[T]] given (elemEq: Eql[T]) {
318318
def eql(x: Tree[T], y: Tree[T]): Boolean = {
319319
val ev = the[Generic[Tree[T]]]
320320
val mx = ev.reflect(x)

docs/docs/reference/contextual-instance/inferable-by-name-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait Codec[T] {
1212

1313
instance intCodec of Codec[Int] = ???
1414

15-
instance optionCodec[T] given (ev: => Codec[T]) of Codec[Option[T]] {
15+
instance optionCodec[T] of Codec[Option[T]] given (ev: => Codec[T]) {
1616
def write(xo: Option[T]) = xo match {
1717
case Some(x) => ev.write(x)
1818
case None =>

docs/docs/reference/contextual-instance/instance-defs.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ instance IntOrd of Ord[Int] {
1919
if (x < y) -1 else if (x > y) +1 else 0
2020
}
2121

22-
instance ListOrd[T] given (ord: Ord[T]) of Ord[List[T]] {
22+
instance ListOrd[T] of Ord[List[T]] given (ord: Ord[T]) {
2323
def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match {
2424
case (Nil, Nil) => 0
2525
case (Nil, _) => -1
@@ -42,9 +42,9 @@ The name of an implicit instance can be left out. So the instance definitions
4242
of the last section can also be expressed like this:
4343
```scala
4444
instance of Ord[Int] { ... }
45-
instance [T] given (ord: Ord[T]) of Ord[List[T]] { ... }
45+
instance [T] of Ord[List[T]] given Ord[T] { ... }
4646
```
47-
If a name is not given, the compiler will synthesize one from the type(s) in the `for` clause.
47+
If a name is not given, the compiler will synthesize one from the type(s) in the `of` clause.
4848

4949
## Alias Instances
5050

@@ -67,12 +67,13 @@ Here is the new syntax of instance definitions, seen as a delta from the [standa
6767
```
6868
TmplDef ::= ...
6969
| ‘instance’ InstanceDef
70-
InstanceDef ::= [id] InstanceParams InstanceBody
71-
InstanceParams ::= [DefTypeParamClause] {GivenParamClause}
70+
InstanceDef ::= [id] [DefTypeParamClause] InstanceBody
71+
InstanceBody ::= [‘of’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
72+
| ‘of’ Type {GivenParamClause} ‘=’ Expr
73+
ConstrApp ::= AnnotType {ArgumentExprs}
74+
| ‘(’ ConstrApp {‘given’ (InfixExpr | ParArgumentExprs)} ‘)’
7275
GivenParamClause ::= ‘given’ (‘(’ [DefParams] ‘)’ | GivenTypes)
73-
InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] [TemplateBody]
74-
| ‘for’ Type ‘=’ Expr
7576
GivenTypes ::= AnnotType {‘,’ AnnotType}
7677
```
77-
The identifier `id` can be omitted only if either the `for` part or the template body is present.
78-
If the `for` part is missing, the template body must define at least one extension method.
78+
The identifier `id` can be omitted only if either the `of` part or the template body is present.
79+
If the `of` part is missing, the template body must define at least one extension method.

docs/docs/reference/contextual-instance/multiversal-equality.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Box[T](x: T) derives Eql
9898
By the usual rules if [typeclass derivation](./derivation.html),
9999
this generates the following `Eql` instance in the companion object of `Box`:
100100
```scala
101-
instance [T, U] given Eql[T, U] of Eql[Box[T], Box[U]] = Eql.derived
101+
instance [T, U] of Eql[Box[T], Box[U]] given Eql[T, U] = Eql.derived
102102
```
103103
That is, two boxes are comparable with `==` or `!=` if their elements are. Examples:
104104
```scala

docs/docs/reference/contextual-instance/relationship-implicits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Instance definitions can be mapped to combinations of implicit objects, classes
2121
```
2222
2. Parameterized instance definitions are mapped to combinations of classes and implicit methods. E.g.,
2323
```scala
24-
instance ListOrd[T] given (ord: Ord[T]) of Ord[List[T]] { ... }
24+
instance ListOrd[T] of Ord[List[T]] given (ord: Ord[T]) { ... }
2525
```
2626
maps to
2727
```scala

0 commit comments

Comments
 (0)