Skip to content

Commit 3738cca

Browse files
authored
Merge pull request scala#1013 from martijnhoekstra/patch-1
try to clarify with a compiling example.
2 parents e15ea35 + 03fa513 commit 3738cca

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

_tour/implicit-conversions.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ Implicit conversions are applied in two situations:
2323
In the first case, a conversion `c` is searched for which is applicable to `e` and whose result type conforms to `T`.
2424
In the second case, a conversion `c` is searched for which is applicable to `e` and whose result contains a member named `m`.
2525

26-
The following operation on the two lists xs and ys of type `List[Int]` is legal:
26+
If an implicit method `List[A] => Ordered[List[A]]` is in scope, as well as an implicit method `Int => Ordered[Int]`, the following operation on the two lists of type `List[Int]` is legal:
2727

2828
```
29-
xs <= ys
29+
List(1, 2, 3) <= List(4, 5)
3030
```
3131

32-
assuming the implicit methods `list2ordered` and `int2ordered` defined below are in scope:
32+
An implicit method `Int => Ordered[Int]` is provided automatically through `scala.Predef.intWrapper`. An example of an implicit method `List[A] => Ordered[List[A]]` is provided below.
33+
34+
```tut
35+
import scala.language.implicitConversions
3336
34-
```
3537
implicit def list2ordered[A](x: List[A])
3638
(implicit elem2ordered: A => Ordered[A]): Ordered[List[A]] =
37-
new Ordered[List[A]] { /* .. */ }
38-
39-
implicit def int2ordered(x: Int): Ordered[Int] =
40-
new Ordered[Int] { /* .. */ }
39+
new Ordered[List[A]] {
40+
//replace with a more useful implementation
41+
def compare(that: List[A]): Int = 1
42+
}
4143
```
4244

4345
The implicitly imported object `scala.Predef` declares several predefined types (e.g. `Pair`) and methods (e.g. `assert`) but also several implicit conversions.

0 commit comments

Comments
 (0)