We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0fde265 commit 243abadCopy full SHA for 243abad
tests/pos/Orderings.scala
@@ -0,0 +1,20 @@
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
+}
0 commit comments