Skip to content

Commit 6a00b2e

Browse files
committed
One more test
1 parent 0fde265 commit 6a00b2e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/pos/Orderings.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
object Orderings {
2+
3+
// A type class:
4+
trait Ord[T] { def less(x: T, y: T): Boolean }
5+
6+
implicit val intOrd: Ord[Int] = new {
7+
def less(x: Int, y: Int) = x < y
8+
}
9+
10+
implicit def listOrd[T](implicit ev: Ord[T]): Ord[List[T]] = new {
11+
def less(xs: List[T], ys: List[T]): Boolean =
12+
if ys.isEmpty then false
13+
else if xs.isEmpty then true
14+
else if xs.head == ys.head then less(xs.tail, ys.tail)
15+
else ev.less(xs.head, ys.head)
16+
}
17+
18+
def isLess[T]: T => T => implicit Ord[T] => Boolean =
19+
x => y => implicitly[Ord[T]].less(x, y)
20+
}
21+
class Misc {
22+
class Context
23+
implicit val ctx: Context
24+
25+
f(2) // OK
26+
f(ctx) // error: found: Context, required: Int
27+
f.explicitly(ctx) // OK
28+
29+
}

0 commit comments

Comments
 (0)