Skip to content

Commit 133928c

Browse files
committed
Test for a new collection class hierarchy respecting mutability
1 parent f9aed5a commit 133928c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package colltestMut
2+
import caps.*
3+
import collection.*, mutable.*, immutable.*
4+
5+
object collection:
6+
trait Iterable[A]:
7+
this: Iterable[A]^ =>
8+
type C[X] <: Iterable[X]^
9+
def map[B](f: A => B): C[B]^{f} = ???
10+
11+
trait View[A] extends Iterable[A]:
12+
this: View[A]^ =>
13+
type C[X] = View[X]^{this}
14+
15+
trait Seq[A] extends Iterable[A]:
16+
this: Seq[A]^ =>
17+
override def map[B](f: A => B): C[B] = ???
18+
19+
object immutable:
20+
import collection.*
21+
trait Seq[A] extends Iterable[A], Pure:
22+
type C[X] <: Seq[X]
23+
24+
class List[A] extends Seq[A]:
25+
type C[X] = List[X]
26+
27+
28+
object mutable:
29+
import collection.*
30+
trait Seq[A] extends collection.Seq[A]:
31+
this: Seq[A]^ =>
32+
type C[X] <: Seq[X]^
33+
34+
trait Buffer[A] extends Seq[A], Mutable:
35+
this: Buffer[A]^ =>
36+
type C[X] = Buffer[X]^
37+
38+
class IO extends SharedCapability
39+
class Ref extends Mutable
40+
41+
object Test:
42+
def test(io: IO, ref: Ref, f: Int => Int) =
43+
val xs1: List[Int] = ???
44+
val ys1 = xs1.map(f)
45+
val xs2: Buffer[Int]^ = ???
46+
val ys2 = xs2.map(f)
47+
val xs3: Buffer[Int]^ = ???
48+
val zs3 = freeze(xs3)
49+
val xs4: Buffer[Int]^ = ???
50+
val vs4: View[Int]^{xs4} = ???
51+
val ys4 = vs4.map(f)

0 commit comments

Comments
 (0)