Skip to content

Commit b5bd2b9

Browse files
committed
Tweaks to wordings in docs
Also: drop some doc pages that are no longer used.
1 parent d53867c commit b5bd2b9

14 files changed

+100
-624
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ A context bound is a shorthand for expressing a common pattern of an inferable p
99
```scala
1010
def maximum[T: Ord](xs: List[T]): T = xs.reduceLeft(max)
1111
```
12-
A bound like `: Ord` on a type parameter `T` of a method or class indicates an inferred parameter `given Ord[T]`. The inferred parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
13-
```
12+
A bound like `: Ord` on a type parameter `T` of a method or class indicates an inferable parameter `given Ord[T]`. The inferable parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
13+
```scala
1414
def f[T: C1 : C2, U: C3](x: T) given (y: U, z: V): R
1515
```
1616
would expand to
17-
```
17+
```scala
1818
def f[T, U](x: T) given (y: U, z: V) given C1[T], C2[T], C3[U]: R
1919
```
2020
Context bounds can be combined with subtype bounds. If both are present, subtype bounds come first, e.g.
21-
```
21+
```scala
2222
def g[T <: B : C](x: T): R = ...
2323
```
2424

docs/docs/reference/contextual/conversions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22
layout: doc-page
3-
title: "Implied Conversions"
3+
title: "Inferable Conversions"
44
---
55

66
Inferable conversions are defined by implied instances of the `scala.Conversion` class.
77
This class is defined in package `scala` as follows:
88
```scala
99
abstract class Conversion[-T, +U] extends (T => U)
1010
```
11-
For example, here is an implied conversion from `String` to `Token`:
11+
For example, here is an inferable conversion from `String` to `Token`:
1212
```scala
1313
implied for Conversion[String, Token] {
1414
def apply(str: String): Token = new KeyWord(str)
1515
}
1616
```
17-
An implied conversion is applied automatically by the compiler in three situations:
17+
An inferable conversion is applied automatically by the compiler in three situations:
1818

1919
1. If an expression `e` has type `T`, and `T` does not conform to the expression's expected type `S`.
2020
2. In a selection `e.m` with `e` of type `T`, but `T` defines no member `m`.

docs/docs/reference/contextual/derivation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ These two conditions ensure that the synthesized derived instances for the trait
4747
```scala
4848
def derived[T] with Generic[T] = ...
4949
```
50-
That is, the `derived` method takes an inferable parameter of type `Generic` that determines the _shape_ of the deriving type `T` and it computes the typeclass implementation according to that shape. A `Generic` instance is generated automatically
51-
for any types that derives a typeclass that needs it. One can also derive `Generic` alone, which means a `Generic` instance is generated without any other type class instances. E.g.:
50+
That is, the `derived` method takes an inferable parameter of type `Generic` that determines the _shape_ of the deriving type `T` and it computes the typeclass implementation according to that shape. An implied `Generic` instance is generated automatically for any type that derives a typeclass with a `derived`
51+
method that refers to `Generic`. One can also derive `Generic` alone, which means a `Generic` instance is generated without any other type class instances. E.g.:
5252
```scala
5353
sealed trait ParseResult[T] derives Generic
5454
```
@@ -97,7 +97,7 @@ Cases[(
9797
Note that an empty element tuple is represented as type `Unit`. A single-element tuple
9898
is represented as `T *: Unit` since there is no direct syntax for such tuples: `(T)` is just `T` in parentheses, not a tuple.
9999

100-
### The Generic TypeClass
100+
### The Generic Typeclass
101101

102102
For every class `C[T_1,...,T_n]` with a `derives` clause, the compiler generates in the companion object of `C` an implied instance of `Generic[C[T_1,...,T_n]]` that follows
103103
the outline below:

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

+14-20
Original file line numberDiff line numberDiff line change
@@ -78,39 +78,39 @@ and where `T` is the expected type. The following two rewritings are tried in or
7878
So `circle.circumference` translates to `CircleOps.circumference(circle)`, provided
7979
`circle` has type `Circle` and `CircleOps` is an eligible implied instance (i.e. it is visible at the point of call or it is defined in the companion object of `Circle`).
8080

81-
## Instances for Extension Methods
81+
### Implied Instances for Extension Methods
8282

83-
Instances that define extension methods can also be defined without an `of` clause. E.g.,
83+
Implied instances that define extension methods can also be defined without an `of` clause. E.g.,
8484

8585
```scala
86-
instance StringOps {
86+
implied StringOps {
8787
def (xs: Seq[String]) longestStrings: Seq[String] = {
8888
val maxLength = xs.map(_.length).max
8989
xs.filter(_.length == maxLength)
9090
}
9191
}
9292

93-
instance ListOps {
93+
implied ListOps {
9494
def (xs: List[T]) second[T] = xs.tail.head
9595
}
9696
```
97-
If such instances are anonymous (as in the examples above), their name is synthesized from the name
97+
If such implied instances are anonymous (as in the examples above), their name is synthesized from the name
9898
of the first defined extension method.
9999

100100
### Operators
101101

102102
The extension method syntax also applies to the definition of operators.
103103
In each case the definition syntax mirrors the way the operator is applied.
104104
Examples:
105-
```
105+
```scala
106106
def (x: String) < (y: String) = ...
107107
def (x: Elem) +: (xs: Seq[Elem]) = ...
108108

109109
"ab" + "c"
110110
1 +: List(2, 3)
111111
```
112112
The two definitions above translate to
113-
```
113+
```scala
114114
def < (x: String)(y: String) = ...
115115
def +: (xs: Seq[Elem])(x: Elem) = ...
116116
```
@@ -120,23 +120,17 @@ to the implementation of right binding operators as normal methods.
120120

121121
### Generic Extensions
122122

123-
The `StringSeqOps` examples extended a specific instance of a generic type. It is also possible to extend a generic type by adding type parameters to an extension method:
123+
The `StringSeqOps` examples extended a specific instance of a generic type. It is also possible to extend a generic type by adding type parameters to an extension method. Examples:
124124

125125
```scala
126-
def (xs: List[T]) second [T] = xs.tail.head
127-
```
128-
129-
or:
126+
def (xs: List[T]) second [T] =
127+
xs.tail.head
130128

129+
def (xs: List[List[T]]) flattened [T] =
130+
xs.foldLeft[List[T]](Nil)(_ ++ _)
131131

132-
```scala
133-
def (xs: List[List[T]]) flattened [T] = xs.foldLeft[List[T]](Nil)(_ ++ _)
134-
```
135-
136-
or:
137-
138-
```scala
139-
def (x: T) + [T : Numeric](y: T): T = implicitly[Numeric[T]].plus(x, y)
132+
def (x: T) + [T : Numeric](y: T): T =
133+
implicitly[Numeric[T]].plus(x, y)
140134
```
141135

142136
As usual, type parameters of the extension method follow the defined method name. Nevertheless, such type parameters can already be used in the preceding parameter clause.

docs/docs/reference/contextual/implicit-conversions.md

-78
This file was deleted.

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: doc-page
33
title: "Inferable By-Name Parameters"
44
---
55

6-
Call-by-name inferable parameters can be used to avoid a divergent inferred expansion.
6+
Inferable by-name parameters can be used to avoid a divergent inferred expansion. Example:
77

88
```scala
99
trait Codec[T] {
@@ -36,16 +36,17 @@ The precise steps for constructing an inferable argument for a by-name parameter
3636
1. Create a new implied instance of type `T`:
3737

3838
```scala
39-
implied for T = ???
39+
implied lv for T = ???
4040
```
41+
where `lv` is an arbitrary fresh name.
4142

42-
1. This instance is not immediately available as candidate for argument inference (making it immediately available would result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an inferred argument to a by-name parameter.
43+
1. This instance is not immediately available as candidate for argument inference (making it immediately available could result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an inferred argument to a by-name parameter.
4344

44-
1. If this search succeeds with expression `E`, and `E` contains references to the implied instance created previously, replace `E` by
45+
1. If this search succeeds with expression `E`, and `E` contains references to the implied instance `lv`, replace `E` by
4546

4647

4748
```scala
48-
{ implied for T = E; lv }
49+
{ implied lv for T = E; lv }
4950
```
5051

5152
Otherwise, return `E` unchanged.

docs/docs/reference/contextual/inferable-params.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ The `infer` method is simply defined as the identity function over an inferable
9494
```scala
9595
def infer[T] given (x: T) = x
9696
```
97-
Functions like `infer` that have only inferable parameters are also called implicit _queries_.
97+
Functions like `infer` that have only inferable parameters are also called _context queries_.
9898

9999
## Syntax
100100

docs/docs/reference/contextual/query-types-spec.md

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
---
22
layout: doc-page
3-
title: "Query Types - More Details"
3+
title: "Context Query Types - More Details"
44
---
55

6-
Initial implementation in (#1775)[https://github.com/lampepfl/dotty/pull/1775].
7-
86
## Syntax
97

108
Type ::= ...
119
| `given' FunArgTypes `=>' Type
1210
Expr ::= ...
1311
| `given' FunParams `=>' Expr
1412

15-
Query types associate to the right, e.g.
13+
Context query types associate to the right, e.g.
1614
`given S => given T => U` is the same as `given S => (given T => U)`.
1715

1816
## Implementation
1917

20-
Query types are shorthands for class types that define `apply`
18+
Context query types are shorthands for class types that define `apply`
2119
methods with inferable parameters. Specifically, the `N`-ary function type
2220
`T1, ..., TN => R` is a shorthand for the class type
2321
`ImplicitFunctionN[T1 , ... , TN, R]`. Such class types are assumed to have the following definitions, for any value of `N >= 1`:
@@ -27,10 +25,10 @@ trait ImplicitFunctionN[-T1 , ... , -TN, +R] {
2725
def apply given (x1: T1 , ... , xN: TN): R
2826
}
2927
```
30-
Query types erase to normal function types, so these classes are
28+
Context query types erase to normal function types, so these classes are
3129
generated on the fly for typechecking, but not realized in actual code.
3230

33-
Query literals `given (x1: T1, ..., xn: Tn) => e` map
31+
Context query literals `given (x1: T1, ..., xn: Tn) => e` map
3432
inferable parameters `xi` of types `Ti` to a result given by expression `e`.
3533
The scope of each implicit parameter `xi` is `e`. The parameters must have pairwise distinct names.
3634

@@ -55,18 +53,17 @@ abbreviated to `given x => e`.
5553
An inferable parameter may also be a wildcard represented by an underscore `_`. In
5654
that case, a fresh name for the parameter is chosen arbitrarily.
5755

58-
Note: The closing paragraph of the [Anonymous Functions section](https://www
59-
.scala-lang.org/files/archive/spec/2.12/06-expressions.html#anonymous-
60-
functions) of the Scala 2.12 is subsumed by query types and should
61-
be removed.
56+
Note: The closing paragraph of the
57+
[Anonymous Functions section](https://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html#anonymous-functions)
58+
of Scala 2.12 is subsumed by query types and should be removed.
6259

6360
Query literals `given (x1: T1, ..., xn: Tn) => e` are
6461
automatically created for any expression `e` whose expected type is
6562
`scala.ImplicitFunctionN[T1, ..., Tn, R]`, unless `e` is
6663
itself a query literal. This is analogous to the automatic
6764
insertion of `scala.Function0` around expressions in by-name argument position.
6865

69-
Query types generalize to `N > 22` in the same way that function types do, see [the corresponding
66+
Context query types generalize to `N > 22` in the same way that function types do, see [the corresponding
7067
documentation](https://dotty.epfl.ch/docs/reference/dropped-features/limit22.html).
7168

7269
## Examples
@@ -79,4 +76,4 @@ Gist](https://gist.github.com/OlivierBlanvillain/234d3927fe9e9c6fba074b53a7bd9
7976

8077
### Type Checking
8178

82-
After desugaring no additional typing rules are required for query types.
79+
After desugaring no additional typing rules are required for context query types.

docs/docs/reference/contextual/query-types.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
layout: doc-page
3-
title: "First Class Queries"
3+
title: "Context Queries"
44
---
55

6-
In the context of inference, _queries_ are functions with inferable parameters.
7-
_Query types_ are the types of first-class queries. Example:
6+
_Context queries_ are functions with inferable parameters.
7+
_Context query types_ are the types of first-class context queries.
8+
Here is an example for a context query type:
89
```scala
910
type Contextual[T] = given Context => T
1011
```
11-
A value of query type is applied to inferred arguments, in
12+
A value of context query type is applied to inferred arguments, in
1213
the same way a method with inferable parameters is applied. For instance:
1314
```scala
1415
implied ctx for Context = ...
@@ -18,9 +19,9 @@ the same way a method with inferable parameters is applied. For instance:
1819
f(2) given ctx // explicit argument
1920
f(2) // argument is inferred
2021
```
21-
Conversely, if the expected type of an expression `E` is a query
22+
Conversely, if the expected type of an expression `E` is a context query
2223
type `given (T_1, ..., T_n) => U` and `E` is not already a
23-
query literal, `E` is converted to a query literal by rewriting to
24+
context query literal, `E` is converted to a context query literal by rewriting to
2425
```scala
2526
given (x_1: T1, ..., x_n: Tn) => E
2627
```
@@ -31,7 +32,7 @@ are available as implied instances in `E`.
3132
Like query types, query literals are written with a `given` prefix. They differ from normal function literals in two ways:
3233

3334
1. Their parameters are inferable.
34-
2. Their types are query types.
35+
2. Their types are context query types.
3536

3637
For example, continuing with the previous definitions,
3738
```scala
@@ -45,7 +46,7 @@ For example, continuing with the previous definitions,
4546
```
4647
### Example: Builder Pattern
4748

48-
Query types have considerable expressive power. For
49+
Context query types have considerable expressive power. For
4950
instance, here is how they can support the "builder pattern", where
5051
the aim is to construct tables like this:
5152
```scala
@@ -111,7 +112,7 @@ With that setup, the table construction code above compiles and expands to:
111112
```
112113
### Example: Postconditions
113114

114-
As a larger example, here is a way to define constructs for checking arbitrary postconditions using `ensuring` so that the checked result can be referred to simply by `result`. The example combines opaque aliases, query 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 `ensuring` so that the checked result can be referred to simply by `result`. The example combines opaque aliases, context query types, and extension methods to provide a zero-overhead abstraction.
115116

116117
```scala
117118
object PostConditions {
@@ -136,7 +137,7 @@ object Test {
136137
val s = List(1, 2, 3).sum.ensuring(result == 6)
137138
}
138139
```
139-
**Explanations**: We use a query type `given WrappedResult[T] => Boolean`
140+
**Explanations**: We use a context query type `given WrappedResult[T] => Boolean`
140141
as the type of the condition of `ensuring`. An argument to `ensuring` such as
141142
`(result == 6)` will therefore have an implied instance of type `WrappedResult[T]` in
142143
scope to pass along to the `result` method. `WrappedResult` is a fresh type, to make sure

0 commit comments

Comments
 (0)