Skip to content

Commit de62914

Browse files
committed
Tests for strict and lazy maps over boxes
1 parent 6cc124e commit de62914

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- [E007] Type Mismatch Error: boxmap.scala:15:2 -------------------------------
2+
15 | () => b[Box[B]]((x: A) => box(f(x)))
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| Found: (() => Box[B]) retains b retains f
5+
| Required: () => Box[B]
6+
|
7+
| where: B is a type in method lazymap with bounds <: Top
8+
9+
longer explanation available when compiling with `-explain`
10+
1 error found
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type Top = Any retains *
2+
class Cap extends Retains[*]
3+
4+
infix type ==> [A, B] = (A => B) retains *
5+
6+
type Box[+T <: Top] = [K <: Top] => (T ==> K) => K
7+
8+
def box[T <: Top](x: T): Box[T] =
9+
[K <: Top] => (k: T ==> K) => k(x)
10+
11+
def map[A <: Top, B <: Top](b: Box[A])(f: A ==> B): Box[B] =
12+
b[Box[B]]((x: A) => box(f(x)))
13+
14+
def lazymap[A <: Top, B <: Top](b: Box[A])(f: A ==> B): () => Box[B] =//retains b.type | f.type =
15+
() => b[Box[B]]((x: A) => box(f(x)))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
type Top = Any retains *
2+
class Cap extends Retains[*]
3+
4+
infix type ==> [A, B] = (A => B) retains *
5+
6+
type Box[+T <: Top] = [K <: Top] => (T ==> K) => K
7+
8+
def box[T <: Top](x: T): Box[T] =
9+
[K <: Top] => (k: T ==> K) => k(x)
10+
11+
def map[A <: Top, B <: Top](b: Box[A])(f: A ==> B): Box[B] =
12+
b[Box[B]]((x: A) => box(f(x)))
13+
14+
def lazymap[A <: Top, B <: Top](b: Box[A])(f: A ==> B): (() => Box[B]) retains b.type | f.type =
15+
() => b[Box[B]]((x: A) => box(f(x)))
16+
17+
def test[A <: Top, B <: Top] =
18+
def lazymap[A <: Top, B <: Top](b: Box[A])(f: A ==> B) =
19+
() => b[Box[B]]((x: A) => box(f(x)))
20+
val x: (b: Box[A]) => (f: A ==> B) => (() => Box[B]) retains b.type | f.type = lazymap[A, B]
21+
()

0 commit comments

Comments
 (0)