Skip to content

Commit f715645

Browse files
committed
Polishings
1 parent 54c5544 commit f715645

10 files changed

+37
-33
lines changed

docs/docs/reference/contextual/conversions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ given as Conversion[String, Token] {
1414
def apply(str: String): Token = new KeyWord(str)
1515
}
1616
```
17-
Using an alias given this can be expressed more concisely as:
17+
Using an alias this can be expressed more concisely as:
1818
```scala
1919
given as Conversion[String, Token] = new KeyWord(_)
2020
```

docs/docs/reference/contextual/delegates.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ SimpleConstrApp ::= AnnotType {ArgumentExprs}
8787
GivenParamClause ::= ‘given’ (‘(’ [DefParams] ‘)’ | GivenTypes)
8888
GivenTypes ::= AnnotType {‘,’ AnnotType}
8989
```
90-
The identifier `id` can be omitted only if either the `for` part or the template body is present.
91-
If the `for` part is missing, the template body must define at least one extension method.
90+
The identifier `id` can be omitted only if either the `as` part or the template body is present.
91+
If the `as` part is missing, the template body must define at least one extension method.

docs/docs/reference/contextual/derivation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ case class Some[T] extends Option[T]
3434
case object None extends Option[Nothing]
3535
```
3636

37-
The generated typeclass delegates are placed in the companion objects `Labelled` and `Option`, respectively.
37+
The generated typeclass instances are placed in the companion objects `Labelled` and `Option`, respectively.
3838

3939
### Derivable Types
4040

4141
A trait or class can appear in a `derives` clause if its companion object defines a method named `derived`. The type and implementation of a `derived` method are arbitrary, but typically it has a definition like this:
4242
```scala
43-
def derived[T] where Mirror.Of[T] = ...
43+
def derived[T] given Mirror.Of[T] = ...
4444
```
4545
That is, the `derived` method takes an implicit parameter of (some subtype of) type `Mirror` that defines the shape of the deriving type `T` and it computes the typeclass implementation according
46-
to that shape. A `Mirror` delegate is generated automatically for
46+
to that shape. A given `Mirror` instance is generated automatically for
4747

4848
- case classes and objects,
4949
- enums and enum cases,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ When is an extension method applicable? There are two possibilities.
3636

3737
- An extension method is applicable if it is visible under a simple name, by being defined
3838
or inherited or imported in a scope enclosing the application.
39-
- An extension method is applicable if it is a member of some instance that is given at the point of the application.
39+
- An extension method is applicable if it is a member of some given instance at the point of the application.
4040

4141
As an example, consider an extension method `longestStrings` on `String` defined in a trait `StringSeqOps`.
4242

@@ -48,15 +48,15 @@ trait StringSeqOps {
4848
}
4949
}
5050
```
51-
We can make the extension method available by defining a given of class `StringSeqOps`, like this:
51+
We can make the extension method available by defining a given `StringSeqOps` instance, like this:
5252
```scala
5353
given ops1 as StringSeqOps
5454
```
5555
Then
5656
```scala
5757
List("here", "is", "a", "list").longestStrings
5858
```
59-
is legal everywhere `ops1` is available as a given instance. Alternatively, we can define `longestStrings` as a member of a normal object. But then the method has to be brought into scope to be usable as an extension method.
59+
is legal everywhere `ops1` is available. Alternatively, we can define `longestStrings` as a member of a normal object. But then the method has to be brought into scope to be usable as an extension method.
6060

6161
```scala
6262
object ops2 extends StringSeqOps
@@ -76,7 +76,7 @@ and where `T` is the expected type. The following two rewritings are tried in or
7676
from `T` to a type containing `m`. If there is more than one way of rewriting, an ambiguity error results.
7777

7878
So `circle.circumference` translates to `CircleOps.circumference(circle)`, provided
79-
`circle` has type `Circle` and `CircleOps` is a given instance (i.e. it is visible at the point of call or it is defined in the companion object of `Circle`).
79+
`circle` has type `Circle` and `CircleOps` is given (i.e. it is visible at the point of call or it is defined in the companion object of `Circle`).
8080

8181
### Given Instances for Extension Methods
8282

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: doc-page
3-
title: "Given Clauses"
3+
title: "Given Parameters"
44
---
55

66
Functional programming tends to express most dependencies as simple function parameterization.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ In the example above, the definition of `s` would be expanded as follows.
5555

5656
```scala
5757
val s = the[Test.Codec[Option[Int]]](
58-
optionCodec[Int](intCodec))
58+
optionCodec[Int](intCodec)
59+
)
5960
```
6061

6162
No local given instance was generated because the synthesized argument is not recursive.

docs/docs/reference/contextual/implicit-function-types-spec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Implicit function types erase to normal function types, so these classes are
2929
generated on the fly for typechecking, but not realized in actual code.
3030

3131
Implicit function literals `given (x1: T1, ..., xn: Tn) => e` map
32-
implicit parameters `xi` of types `Ti` to the result of evaluating expression `e`.
32+
implicit parameters `xi` of types `Ti` to the result of evaluating the expression `e`.
3333
The scope of each implicit parameter `xi` is `e`. The parameters must have pairwise distinct names.
3434

3535
If the expected type of the implicit function literal is of the form
@@ -42,7 +42,7 @@ type of `e`. `T` must be equivalent to a type which does not refer to any of
4242
the implicit parameters `xi`.
4343

4444
The implicit function literal is evaluated as the instance creation
45-
expression:
45+
expression
4646
```scala
4747
new scala.ImplicitFunctionN[T1, ..., Tn, T] {
4848
def apply given (x1: T1, ..., xn: Tn): T = e

docs/docs/reference/contextual/implicit-function-types.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ the same way a method with a given clause is applied. For instance:
1919
f(2) given ec // explicit argument
2020
f(2) // argument is inferred
2121
```
22-
def foo[T](x: T, y: T) given Ord[T], {x < y}: ....
23-
2422
Conversely, if the expected type of an expression `E` is an implicit function type
2523
`given (T_1, ..., T_n) => U` and `E` is not already an
2624
implicit function literal, `E` is converted to an implicit function literal by rewriting to
@@ -29,7 +27,7 @@ implicit function literal, `E` is converted to an implicit function literal by r
2927
```
3028
where the names `x_1`, ..., `x_n` are arbitrary. This expansion is performed
3129
before the expression `E` is typechecked, which means that `x_1`, ..., `x_n`
32-
are given instances in `E`.
30+
are available as givens in `E`.
3331

3432
Like their types, implicit function literals are written with a `given` prefix. They differ from normal function literals in two ways:
3533

@@ -42,7 +40,7 @@ For example, continuing with the previous definitions,
4240

4341
g(22) // is expanded to g(given ev => 22)
4442

45-
g(f(2)) // is expanded to g(given ev => f(2) given ev)
43+
g(f(2)) // is expanded to g(given ev => (f(2) given ev))
4644

4745
g(given ctx => f(22) given ctx) // is left as it is
4846
```
@@ -90,31 +88,31 @@ that would otherwise be necessary.
9088
t
9189
}
9290

93-
def row(init: given Row => Unit) where (t: Table) = {
91+
def row(init: given Row => Unit) given (t: Table) = {
9492
given r as Row
9593
init
9694
t.add(r)
9795
}
9896

99-
def cell(str: String) where (r: Row) =
97+
def cell(str: String) given (r: Row) =
10098
r.add(new Cell(str))
10199
```
102100
With that setup, the table construction code above compiles and expands to:
103101
```scala
104102
table { given ($t: Table) =>
105103
row { given ($r: Row) =>
106-
cell("top left") where $r
107-
cell("top right") where $r
108-
} where $t
104+
cell("top left") given $r
105+
cell("top right") given $r
106+
} given $t
109107
row { given ($r: Row) =>
110-
cell("bottom left") where $r
111-
cell("bottom right") where $r
112-
} where $t
108+
cell("bottom left") given $r
109+
cell("bottom right") given $r
110+
} given $t
113111
}
114112
```
115113
### Example: Postconditions
116114

117-
As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring`so that the checked result can be referred to simply by `result`. The example combines opaque aliases, implicit function types, and extension methods to provide a zero-overhead abstraction.
115+
As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring` so that the checked result can be referred to simply by `result`. The example combines opaque aliases, implicit function types, and extension methods to provide a zero-overhead abstraction.
118116

119117
```scala
120118
object PostConditions {
@@ -123,7 +121,7 @@ object PostConditions {
123121
def result[T] given (r: WrappedResult[T]): T = r
124122

125123
def (x: T)
126-
ensuring [T] (condition: given WrappedResult[T] => Boolean): T =
124+
ensuring[T](condition: given WrappedResult[T] => Boolean): T =
127125
assert(condition) given x
128126
}
129127
import PostConditions.{ensuring, result}

docs/docs/reference/contextual/import-delegate.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ Since givens can be anonymous it is not always practical to import them by their
3636
```scala
3737
import given A.{_: TC}
3838
```
39-
This imports any given in `A` that has a type which conforms to `TC`. There can be several bounding types following a `_ :` and bounding types can contain wildcards.
39+
This imports any given in `A` that has a type which conforms to `TC`. Importing givens of several types `T1,...,Tn`
40+
is expressed by bounding with a union type.
41+
```
42+
import given A.{_: T1 | ... | Tn}
43+
```
44+
Importing all instances of a parameterized if expressed by wildcard arguments.
4045
For instance, assuming the object
4146
```scala
4247
object Instances {
@@ -48,15 +53,15 @@ object Instances {
4853
```
4954
the import
5055
```scala
51-
import given Instances.{_: Ordering[_] | ExecutionContext}
56+
import given Instances.{_: Ordering[?] | ExecutionContext}
5257
```
5358
would import the `intOrd`, `listOrd`, and `ec` instances but leave out the `im` instance, since it fits none of the specified bounds.
5459

5560
By-type imports can be mixed with by-name imports. If both are present in an import clause, by-type imports come last. For instance, the import clause
5661
```scala
57-
import given Instances.{im, _: Ordering[_]}
62+
import given Instances.{im, _: Ordering[?]}
5863
```
59-
would import `im`, `intOrd`, and `listOrd` but leave out `ec`. By-type imports cannot be mixed with a wildcard import in the same import clause.
64+
would import `im`, `intOrd`, and `listOrd` but leave out `ec`.
6065

6166
Bounded wildcard selectors also work for normal imports and exports. For instance, consider the following `enum` definition:
6267
```scala

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ get their name from the name of the first extension method and the toplevel type
7575
constructor of its first parameter. For example, the given instance
7676
```scala
7777
given {
78-
def (xs: List[T]) second[T] = ...
78+
def (xs: List[T]) second[T] = ...
7979
}
8080
```
8181
gets the synthesized name `second_of_List_T_given`.

0 commit comments

Comments
 (0)