Skip to content

Commit f8496bd

Browse files
author
Martijn Hoekstra
committed
polish
1 parent feff51f commit f8496bd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

_tour/multiple-parameter-lists.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Suggested use cases for multiple parameter lists include:
3838

3939
#### Drive type inference
4040

41+
It so happens that in Scala, type inference proceeds one parameter list at at time.
4142
Say, you have the following method:
4243

4344
```tut
@@ -57,14 +58,14 @@ def firstWay = foldleft1[Int, Int](numbers, 0, _ + _)
5758
def secondWay = foldleft1(numbers, 0, (a: Int, b: Int) => a + b)
5859
```
5960

60-
That's because scala won't be able to infer the type of the function `_ + _`, as it's still inferring `A` and `B`. By moving the paramter `op` to its own parameter list, `A` and `B` have been inferred, and `_ + _` will match the the inferred type `(Int, Int) => Int`
61+
That's because scala won't be able to infer the type of the function `_ + _`, as it's still inferring `A` and `B`. By moving the parameter `op` to its own parameter list, `A` and `B` are inferred in the first parameter list. These inferred types will then be available to the second parameter list and `_ + _` will match the the inferred type `(Int, Int) => Int`
6162

6263
```tut
6364
def foldleft2[A, B](as: List[A], b0: B)(op: (B, A) => B) = ???
6465
def possible = foldleft2(numbers, 0)(_ + _)
6566
```
6667

67-
This definition doesn't need any type hints, and can infer all of its parameters.
68+
This definition doesn't need any type hints and can infer all of its parameters.
6869

6970

7071
#### Implicit parameters

0 commit comments

Comments
 (0)