You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/auto-parameter-tupling-spec.md
+9-10Lines changed: 9 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ xs.map {
18
18
case (x, y) => x + y
19
19
}
20
20
```
21
-
While correct, this is also inconvenient. Instead, automatic tupling of function parameters proposed to be able to write it the following way:
21
+
While correct, this is inconvenient. Instead, we propose to be able to write it the following way:
22
22
23
23
```scala
24
24
xs.map {
@@ -30,21 +30,20 @@ or, equivalently:
30
30
xs.map(_ + _)
31
31
```
32
32
33
-
Generally, a function value with `n > 1` parameters can be converted to a pattern-matching closure using case if the expected type is a unary function type of the form `((T_1, ..., T_n)) => U`.
33
+
Generally, a function value with `n > 1` parameters can be converted to a function with tupled arguments if the expected type is a unary function type of the form `((T_1, ..., T_n)) => U`.
34
34
35
35
### Type Checking
36
36
37
-
Let a function `F` of the form `F = (p1, ..., pn) => E` for `n != 1`, parameters `p1, ..., pn`, and an expression `E`.
37
+
Let a function `f` of the form `(p1, ..., pn) => e` for `n != 1`, parameters `p1, ..., pn`, and an expression `e`.
38
38
39
-
40
-
If the expected type of `F` is a fully defined function type or SAM-type that has a
39
+
If the expected type of `f` is a fully defined function type or SAM-type that has a
41
40
single parameter of a subtype of `ProductN[T1, ..., Tn]`, where each type `Ti` fits the corresponding
42
41
parameter `pi`.
43
42
44
-
A type `T` fits a parameter `p` if one of the following two cases is `true`:
43
+
A type `Ti` fits a parameter `pi` if one of the following two cases is `true`:
45
44
46
-
*`p` comes without a type, i.e. it is a simple identifier or `_`.
47
-
*`p` is of the form `x: U` or `_: U` and `T` conforms to `U`.
45
+
*`pi` comes without a type, i.e. it is a simple identifier or `_`.
46
+
*`pi` is of the form `x: Ui` or `_: Ui` and `Ti` conforms to `Ui`.
48
47
49
48
Auto-tupling composes with eta-expansion. That is an n-ary function generated by eta-expansion
50
49
can in turn be adapted to the expected type with auto-tupling.
@@ -74,9 +73,9 @@ Translation of such a tuples would use the `apply` method on the tuple to access
74
73
75
74
### Migration
76
75
77
-
Code like this could not be written before, hence the new notation would not be ambigouous after addoptation.
76
+
Code like this could not be written before, hence the new notation would not be ambigouous after adoption.
78
77
79
-
Thought it is possible that someone has written an implicit conversion for`(T1, ..., Tn) => R`into`TupleN[T1, ..., Tn]`
78
+
Though it is possible that someone has written an implicit conversion form`(T1, ..., Tn) => R`to`TupleN[T1, ..., Tn] => R`
80
79
for some `n`. This change could be detected and fixed by `Scalafix`. Furthermore, such conversion would probably
81
80
be doing the same translation (semantically) but in a less efficient way.
0 commit comments