Skip to content

Commit c204ab0

Browse files
committed
Doc changes
1 parent 928e01a commit c204ab0

21 files changed

+160
-100
lines changed

docs/docs/internals/syntax.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,11 @@ Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[
205205
| [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
206206
| SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr)
207207
| PostfixExpr [Ascription]
208+
| StructuralInstance
208209
| ‘inline’ InfixExpr MatchClause
209210
Ascription ::= ‘:’ InfixType Typed(expr, tp)
210211
| ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*)
212+
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ TemplateBody] New templ
211213
Catches ::= ‘catch’ (Expr | ExprCaseClause)
212214
PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op)
213215
InfixExpr ::= PrefixExpr
@@ -396,9 +398,8 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
396398
ConstrMods ::= {Annotation} [AccessModifier]
397399
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
398400
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
399-
GivenDef ::= [GivenSig] Type ‘=’ Expr
400-
| [GivenSig] ConstrApps [TemplateBody]
401-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’ -- one of `id`, `DefParamClause`, `UsingParamClause` must appear
401+
GivenDef ::= [GivenSig] (Type [‘=’ Expr] | StructuralInstance)
402+
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefParamClause`, `UsingParamClause` must be present
402403
Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
403404
{UsingParamClause}] ExtMethods
404405
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’

docs/docs/reference/changed-features/implicit-resolution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ no longer applies.
4141
**3.** Package prefixes no longer contribute to the implicit search scope of a type. Example:
4242
```scala
4343
package p
44-
given a as A
44+
given a: A = A()
4545

4646
object o {
47-
given b as B
47+
given b: B = B()
4848
type C
4949
}
5050
```

docs/docs/reference/changed-features/numeric-literals.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,38 +133,32 @@ should produce the `BigFloat` number `BigFloat(-123, 997)`:
133133
The companion object of `BigFloat` defines an `apply` constructor method to construct a `BigFloat`
134134
from a `digits` string. Here is a possible implementation:
135135
```scala
136-
object BigFloat {
136+
object BigFloat:
137137
import scala.util.FromDigits
138138

139-
def apply(digits: String): BigFloat = {
140-
val (mantissaDigits, givenExponent) = digits.toUpperCase.split('E') match {
139+
def apply(digits: String): BigFloat =
140+
val (mantissaDigits, givenExponent) = digits.toUpperCase.split('E') match
141141
case Array(mantissaDigits, edigits) =>
142142
val expo =
143143
try FromDigits.intFromDigits(edigits)
144-
catch {
145-
case ex: FromDigits.NumberTooLarge =>
146-
throw FromDigits.NumberTooLarge(s"exponent too large: $edigits")
147-
}
144+
catch case ex: FromDigits.NumberTooLarge =>
145+
throw FromDigits.NumberTooLarge(s"exponent too large: $edigits")
148146
(mantissaDigits, expo)
149147
case Array(mantissaDigits) =>
150148
(mantissaDigits, 0)
151-
}
152-
val (intPart, exponent) = mantissaDigits.split('.') match {
149+
val (intPart, exponent) = mantissaDigits.split('.') match
153150
case Array(intPart, decimalPart) =>
154151
(intPart ++ decimalPart, givenExponent - decimalPart.length)
155152
case Array(intPart) =>
156153
(intPart, givenExponent)
157-
}
158154
BigFloat(BigInt(intPart), exponent)
159-
}
160155
```
161156
To accept `BigFloat` literals, all that's needed in addition is a `given` instance of type
162157
`FromDigits.Floating[BigFloat]`:
163158
```scala
164-
given FromDigits as FromDigits.Floating[BigFloat] {
159+
given FromDigits: FromDigits.Floating[BigFloat] with
165160
def fromDigits(digits: String) = apply(digits)
166-
}
167-
} // end BigFloat
161+
end BigFloat
168162
```
169163
Note that the `apply` method does not check the format of the `digits` argument. It is
170164
assumed that only valid arguments are passed. For calls coming from the compiler

docs/docs/reference/changed-features/structural-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ than other classes. Here is an example:
131131
trait Vehicle extends reflect.Selectable {
132132
val wheels: Int
133133
}
134-
val i3 = new Vehicle { // i3: Vehicle { val range: Int }
134+
val i3 = Vehicle with { // i3: Vehicle { val range: Int }
135135
val wheels = 4
136136
val range = 240
137137
}

docs/docs/reference/contextual/by-name-context-parameters.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ trait Codec[T] {
1010
def write(x: T): Unit
1111
}
1212

13-
given intCodec as Codec[Int] = ???
13+
given intCodec: Codec[Int] = ???
1414

15-
given optionCodec[T](using ev: => Codec[T]) as Codec[Option[T]] {
16-
def write(xo: Option[T]) = xo match {
15+
given optionCodec[T](using ev: => Codec[T]): Codec[Option[T]] with
16+
def write(xo: Option[T]) = xo match
1717
case Some(x) => ev.write(x)
1818
case None =>
19-
}
20-
}
2119

2220
val s = summon[Codec[Option[Int]]]
2321

@@ -36,7 +34,7 @@ The precise steps for synthesizing an argument for a by-name context parameter o
3634
1. Create a new given of type `T`:
3735

3836
```scala
39-
given lv as T = ???
37+
given lv: T = ???
4038
```
4139
where `lv` is an arbitrary fresh name.
4240

@@ -46,7 +44,7 @@ The precise steps for synthesizing an argument for a by-name context parameter o
4644

4745

4846
```scala
49-
{ given lv as T = E; lv }
47+
{ given lv: T = E; lv }
5048
```
5149

5250
Otherwise, return `E` unchanged.

docs/docs/reference/contextual/context-functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Context functions are written using `?=>` as the "arrow" sign.
1313
They are applied to synthesized arguments, in
1414
the same way methods with context parameters are applied. For instance:
1515
```scala
16-
given ec as ExecutionContext = ...
16+
given ec: ExecutionContext = ...
1717

1818
def f(x: Int): ExecutionContext ?=> Int = ...
1919

@@ -86,13 +86,13 @@ with context function types as parameters to avoid the plumbing boilerplate
8686
that would otherwise be necessary.
8787
```scala
8888
def table(init: Table ?=> Unit) = {
89-
given t as Table // note the use of a creator application; same as: given t as Table = new Table
89+
given t: Table = Table()
9090
init
9191
t
9292
}
9393

9494
def row(init: Row ?=> Unit)(using t: Table) = {
95-
given r as Row
95+
given r: Row = Row()
9696
init
9797
t.add(r)
9898
}

docs/docs/reference/contextual/conversions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ If such an instance `C` is found, the expression `e` is replaced by `C.apply(e)`
3737
primitive number types to subclasses of `java.lang.Number`. For instance, the
3838
conversion from `Int` to `java.lang.Integer` can be defined as follows:
3939
```scala
40-
given int2Integer as Conversion[Int, java.lang.Integer] =
40+
given int2Integer: Conversion[Int, java.lang.Integer] =
4141
java.lang.Integer.valueOf(_)
4242
```
4343

@@ -59,9 +59,9 @@ object Completions {
5959
//
6060
// CompletionArg.fromStatusCode(statusCode)
6161

62-
given fromString as Conversion[String, CompletionArg] = Error(_)
63-
given fromFuture as Conversion[Future[HttpResponse], CompletionArg] = Response(_)
64-
given fromStatusCode as Conversion[Future[StatusCode], CompletionArg] = Status(_)
62+
given fromString : Conversion[String, CompletionArg] = Error(_)
63+
given fromFuture : Conversion[Future[HttpResponse], CompletionArg] = Response(_)
64+
given fromStatusCode : Conversion[Future[StatusCode], CompletionArg] = Status(_)
6565
}
6666
import CompletionArg._
6767

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that
2525
produces a quoted instance for `Eq[T]`. Here is a possible signature,
2626

2727
```scala
28-
given derived[T: Type](using Quotes) as Expr[Eq[T]]
28+
given derived[T: Type](using Quotes): Expr[Eq[T]]
2929
```
3030

3131
and for comparison reasons we give the same signature we had with `inline`:
3232

3333
```scala
34-
inline given derived[T] as (m: Mirror.Of[T]) => Eq[T] = ???
34+
inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = ???
3535
```
3636

3737
Note, that since a type is used in a subsequent stage it will need to be lifted
@@ -41,7 +41,7 @@ from the signature. The body of the `derived` method is shown below:
4141

4242

4343
```scala
44-
given derived[T: Type](using Quotes) as Expr[Eq[T]] = {
44+
given derived[T: Type](using Quotes): Expr[Eq[T]] = {
4545
import quotes.reflect._
4646

4747
val ev: Expr[Mirror.Of[T]] = Expr.summon[Mirror.Of[T]].get
@@ -176,7 +176,7 @@ object Eq {
176176
case '[EmptyTuple] => Nil
177177
}
178178

179-
given derived[T: Type](using q: Quotes) as Expr[Eq[T]] = {
179+
given derived[T: Type](using q: Quotes): Expr[Eq[T]] = {
180180
import quotes.reflect._
181181

182182
val ev: Expr[Mirror.Of[T]] = Expr.summon[Mirror.Of[T]].get

docs/docs/reference/contextual/derivation.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ The `derives` clause generates the following given instances for the `Eq`, `Orde
1919
companion object of `Tree`,
2020

2121
```scala
22-
given [T: Eq] as Eq[Tree[T]] = Eq.derived
23-
given [T: Ordering] as Ordering[Tree] = Ordering.derived
24-
given [T: Show] as Show[Tree] = Show.derived
22+
given [T: Eq] : Eq[Tree[T]] = Eq.derived
23+
given [T: Ordering] : Ordering[Tree] = Ordering.derived
24+
given [T: Show] : Show[Tree] = Show.derived
2525
```
2626

2727
We say that `Tree` is the _deriving type_ and that the `Eq`, `Ordering` and `Show` instances are _derived instances_.
@@ -179,7 +179,7 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that
179179
a `Mirror[T]`. Here is a possible implementation,
180180

181181
```scala
182-
inline given derived[T](using m: Mirror.Of[T]) as Eq[T] = {
182+
inline given derived[T](using m: Mirror.Of[T]): Eq[T] = {
183183
val elemInstances = summonAll[m.MirroredElemTypes] // (1)
184184
inline m match { // (2)
185185
case s: Mirror.SumOf[T] => eqSum(s, elemInstances)
@@ -278,7 +278,7 @@ object Eq {
278278
}
279279
}
280280

281-
inline given derived[T](using m: Mirror.Of[T]) as Eq[T] = {
281+
inline given derived[T](using m: Mirror.Of[T]): Eq[T] = {
282282
lazy val elemInstances = summonAll[m.MirroredElemTypes]
283283
inline m match {
284284
case s: Mirror.SumOf[T] => eqSum(s, elemInstances)
@@ -309,7 +309,7 @@ In this case the code that is generated by the inline expansion for the derived
309309
following, after a little polishing,
310310

311311
```scala
312-
given derived$Eq[T](using eqT: Eq[T]) as Eq[Opt[T]] =
312+
given derived$Eq[T](using eqT: Eq[T]): Eq[Opt[T]] =
313313
eqSum(summon[Mirror[Opt[T]]],
314314
List(
315315
eqProduct(summon[Mirror[Sm[T]]], List(summon[Eq[T]]))
@@ -326,13 +326,13 @@ As a third example, using a higher level library such as shapeless the type clas
326326
`derived` method as,
327327

328328
```scala
329-
given eqSum[A](using inst: => K0.CoproductInstances[Eq, A]) as Eq[A] {
329+
given eqSum[A](using inst: => K0.CoproductInstances[Eq, A]): Eq[A] {
330330
def eqv(x: A, y: A): Boolean = inst.fold2(x, y)(false)(
331331
[t] => (eqt: Eq[t], t0: t, t1: t) => eqt.eqv(t0, t1)
332332
)
333333
}
334334

335-
given eqProduct[A](using inst: K0.ProductInstances[Eq, A]) as Eq[A] {
335+
given eqProduct[A](using inst: K0.ProductInstances[Eq, A]): Eq[A] {
336336
def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)(
337337
[t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) => Complete(!eqt.eqv(t0, t1))(false)(true)
338338
)
@@ -354,7 +354,7 @@ change the code of the ADT itself. To do this, simply define an instance using
354354
as right-hand side. E.g, to implement `Ordering` for `Option` define,
355355

356356
```scala
357-
given [T: Ordering] as Ordering[Option[T]] = Ordering.derived
357+
given [T: Ordering]: Ordering[Option[T]] = Ordering.derived
358358
```
359359

360360
Assuming the `Ordering.derived` method has a context parameter of type `Mirror[T]` it will be satisfied by the

docs/docs/reference/contextual/extension-methods.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension (x: String)
4040
extension (x: Elem)
4141
def +: (xs: Seq[Elem]): Seq[Elem] = ...
4242
extension (x: Number)
43-
@infix def min (y: Number): Number = ...
43+
infix def min (y: Number): Number = ...
4444

4545
"ab" < "c"
4646
1 +: List(2, 3)
@@ -52,7 +52,7 @@ The three definitions above translate to
5252
```scala
5353
<extension> def < (x: String)(y: String): Boolean = ...
5454
<extension> def +: (xs: Seq[Elem])(x: Elem): Seq[Elem] = ...
55-
@infix <extension> def min(x: Number)(y: Number): Number = ...
55+
<extension> infix def min(x: Number)(y: Number): Number = ...
5656
```
5757

5858
Note the swap of the two parameters `x` and `xs` when translating
@@ -194,7 +194,7 @@ trait SafeDiv:
194194
By the second rule, an extension method can be made available by defining a given instance containing it, like this:
195195

196196
```scala
197-
given ops1 as IntOps // brings safeMod into scope
197+
given ops1: IntOps with {} // brings safeMod into scope
198198

199199
1.safeMod(2)
200200
```
@@ -209,7 +209,7 @@ object List:
209209
extension [T](xs: List[List[T]])
210210
def flatten: List[T] = xs.foldLeft(Nil: List[T])(_ ++ _)
211211

212-
given [T: Ordering] as Ordering[List[T]]:
212+
given [T: Ordering]: Ordering[List[T]] with
213213
extension (xs: List[T])
214214
def < (ys: List[T]): Boolean = ...
215215
end List

docs/docs/reference/contextual/given-imports.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A special form of import wildcard selector is used to import given instances. Ex
88
```scala
99
object A {
1010
class TC
11-
given tc as TC
11+
given tc: TC = ???
1212
def f(using TC) = ???
1313
}
1414

@@ -60,10 +60,10 @@ For instance, assuming the object
6060

6161
```scala
6262
object Instances {
63-
given intOrd as Ordering[Int]
64-
given listOrd[T: Ordering] as Ordering[List[T]]
65-
given ec as ExecutionContext = ...
66-
given im as Monoid[Int]
63+
given intOrd: Ordering[Int] = ...
64+
given listOrd[T: Ordering]: Ordering[List[T]] = ...
65+
given ec: ExecutionContext = ...
66+
given im: Monoid[Int] = ...
6767
}
6868
```
6969

0 commit comments

Comments
 (0)