6
6
M.Impl[T[_]] = Common { type This = T }
7
7
...
8
8
9
+ - Common definitions in traits may not see trait parameters, but common definitions
10
+ in classes may see class parameters.
11
+
9
12
- An extension trait is a trait that uses This or a trait inheriting an extension trait.
10
13
- The kind of `This` is the kind of the extension trait.
11
14
- Extension traits of different kinds cannot inherit each other and cannot be mixed using `with`.
@@ -80,11 +83,16 @@ object runtime {
80
83
def length: Int
81
84
}
82
85
86
+ trait Cmp[A] {
87
+ def isSimilar(x: A): Boolean
88
+ common def exact: Boolean
89
+ }
90
+
83
91
trait HasBoundedLength extends HasLength {
84
92
common def limit: Int
85
93
}
86
94
87
- extension trait HasBoundedLengthX extends HasBoundedLength {
95
+ trait HasBoundedLengthX extends HasBoundedLength {
88
96
common def longest: This
89
97
}
90
98
@@ -96,12 +104,16 @@ object runtime {
96
104
def length = xs.length
97
105
}
98
106
99
- class C2(xs: Array[Int]) extends C1(xs) with HasBoundedLength {
107
+ class C2(xs: Array[Int]) extends C1(xs) with HasBoundedLength with Cmp[Seq[Int]] {
108
+ def isSimilar(x: Seq[Int]) = xs.deep == x
100
109
common def limit = 100
110
+ common def exact = true
101
111
}
102
112
103
- class CG2[T](xs: Array[Int]) extends CG1[T](xs) with HasBoundedLength {
113
+ class CG2[T](xs: Array[Int]) extends CG1[T](xs) with HasBoundedLength with Cmp[Seq[T]] {
114
+ def isSimilar(x: Seq[T]) = xs.deep == x
104
115
common def limit = 100
116
+ common def exact = true
105
117
}
106
118
107
119
final class C3(xs: Array[Int]) extends C2(xs) with HasBoundedLengthX {
@@ -237,6 +249,20 @@ object hasLength {
237
249
def length : Int
238
250
}
239
251
252
+ trait Cmp [A ] extends TypeClass {
253
+ val `common` : HasBoundedLength .Common
254
+ import `common` ._
255
+ def isSimilar (x : A ): Boolean
256
+ }
257
+
258
+ object Cmp extends TypeClass .Companion {
259
+ trait Common extends TypeClass .Common {
260
+ type Instance <: HasBoundedLength
261
+ def exact : Boolean
262
+ }
263
+ }
264
+
265
+
240
266
trait HasBoundedLength extends HasLength with TypeClass {
241
267
val `common` : HasBoundedLength .Common
242
268
import `common` ._
@@ -264,27 +290,31 @@ object hasLength {
264
290
265
291
class C1 (xs : Array [Int ]) extends HasLength {
266
292
def length = xs.length
293
+ def isSimilar (x : Seq [Int ]) = xs.deep == x
267
294
}
268
295
269
296
class CG1 [T ](xs : Array [T ]) extends HasLength {
270
297
def length = xs.length
298
+ def isSimilar (x : Seq [T ]) = xs.deep == x
271
299
}
272
300
273
- class C2 (xs : Array [Int ]) extends C1 (xs) with HasBoundedLength {
301
+ class C2 (xs : Array [Int ]) extends C1 (xs) with HasBoundedLength with Cmp [ Seq [ Int ]] {
274
302
val `common` : C2Common = C2
275
303
import `common` ._
276
304
}
277
- abstract class C2Common extends HasBoundedLength .Common {
305
+ abstract class C2Common extends HasBoundedLength .Common with Cmp . Common {
278
306
def limit = 100
307
+ def exact = true
279
308
}
280
309
object C2 extends C2Common with SubtypeInjector [C2 ]
281
310
282
- class CG2 [T ](xs : Array [T ]) extends CG1 (xs) with HasBoundedLength {
311
+ class CG2 [T ](xs : Array [T ]) extends CG1 (xs) with HasBoundedLength with Cmp [ Seq [ T ]] {
283
312
val `common` : CG2Common [T ] = CG2 [T ]
284
313
import `common` ._
285
314
}
286
- abstract class CG2Common [T ] extends HasBoundedLength .Common {
315
+ abstract class CG2Common [T ] extends HasBoundedLength .Common with Cmp . Common {
287
316
def limit = 100
317
+ def exact = true
288
318
}
289
319
object CG2 {
290
320
def apply [T ] = new CG2Common [T ] with SubtypeInjector [CG2 [T ]]
0 commit comments