File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ object Test {
2
+
3
+ type T = String
4
+
5
+ class Ord [T ]
6
+ implicit def listOrd [T ](implicit o : Ord [T ]): Ord [List [T ]] = ???
7
+ implicit def intOrd : Ord [Int ] = ???
8
+
9
+ def sort [T ](xs : List [T ])(implicit o : Ord [T ]): List [T ] = ???
10
+
11
+ def g (xs : List [Int ]) =
12
+ sort(xs)
13
+
14
+ def f [T ](xs : List [List [List [T ]]]) =
15
+ sort(xs) // error TODO: improve the -explain-implicts diagnostic
16
+
17
+ listOrd(listOrd(implicitly[Ord [T ]] /* not found*/ )) // error
18
+ }
Original file line number Diff line number Diff line change
1
+ package cm
2
+
3
+ case class Person (name : String )
4
+ case class Paper (title : String , authors : List [Person ], body : String )
5
+
6
+ class Viewers (val persons : Set [Person ])
7
+
8
+ class ConfManagement (papers : List [Paper ], realScore : Map [Paper , Int ]) {
9
+
10
+ private def hasConflict (ps1 : Set [Person ], ps2 : Iterable [Person ]) =
11
+ ps2.exists(ps1 contains _)
12
+
13
+ def viewers (implicit vs : Viewers ): Set [Person ] =
14
+ vs.persons
15
+
16
+ def score (paper : Paper )(implicit vs : Viewers ): Int =
17
+ if (hasConflict(viewers, paper.authors)) - 100
18
+ else realScore(paper)
19
+
20
+ def viewRankings (implicit vs : Viewers ): List [Paper ] =
21
+ papers.sortBy(score(_))
22
+
23
+ def delegate [T ](query : Viewers => T , p : Person )(implicit vs : Viewers ): T =
24
+ query(new Viewers (viewers + p))
25
+ }
Original file line number Diff line number Diff line change
1
+ trait Eq [T ] {
2
+ def eq (a : T , b : T ): Boolean
3
+ }
4
+
5
+ object Eq {
6
+ implicit object int extends Eq [Int ] {
7
+ def eq (a : Int , b : Int ) = a == b
8
+ }
9
+ }
10
+
11
+ object Test {
12
+ def f [T ](a : T , b : T )(implicit T : Eq [T ]) = T .eq(a, b)
13
+
14
+ def main (args : Array [String ]) =
15
+ assert(! f(1 , 2 ))
16
+ }
You can’t perform that action at this time.
0 commit comments