Skip to content

Commit e685926

Browse files
committed
Add boxmap test from paper
1 parent 87aa777 commit e685926

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CheckCaptures extends Recheck:
8080
import ast.tpd.*
8181

8282
override def reinfer(tp: Type)(using Context): Type =
83-
CapturingType(tp, CaptureSet.Var())
83+
CapturingType(tp, CaptureSet.Var()) // ^^^ go deep
8484

8585
private var curEnv: Env = Env(NoSymbol, CaptureSet.empty, false, null)
8686

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
infix type ==> [A, B] = (A => B) retains *
2+
3+
type Cell[+T] = [K] => (T ==> K) => K
4+
5+
def cell[T](x: T): Cell[T] =
6+
[K] => (k: T ==> K) => k(x)
7+
8+
def get[T](c: Cell[T]): T = c[T](identity[T]) // TODO: drop [T]
9+
10+
def map[A, B](c: Cell[A])(f: A ==> B): Cell[B]
11+
= c[Cell[B]]((x: A) => cell(f(x)))
12+
13+
def pureMap[A, B](c: Cell[A])(f: A => B): Cell[B]
14+
= c[Cell[B]]((x: A) => cell(f(x)))
15+
16+
def lazyMap[A, B](c: Cell[A])(f: A ==> B): {f} () => Cell[B]
17+
= () => c[Cell[B]]((x: A) => cell(f(x)))
18+
19+
trait IO:
20+
def print(s: String): Unit
21+
22+
def test(io: {*} IO) =
23+
24+
val loggedOne: {io} () => Int = () => { io.print("1"); 1 }
25+
26+
val c: Cell[{io} () => Int]
27+
= cell[{io} () => Int](loggedOne)
28+
29+
val g = (f: {io} () => Int) =>
30+
val x = f(); io.print(" + ")
31+
val y = f(); io.print(s" = ${x + y}")
32+
33+
val r = lazyMap[{io} () => Int, Unit](c)(f => g(f))
34+
val r2 = lazyMap[{io} () => Int, Unit](c)(g)
35+
// val r3 = lazyMap(c)(g) not yet
36+
val _ = r()
37+
val _ = r2()
38+
// val _ = r3()

0 commit comments

Comments
 (0)