File tree Expand file tree Collapse file tree 5 files changed +130
-0
lines changed Expand file tree Collapse file tree 5 files changed +130
-0
lines changed Original file line number Diff line number Diff line change 1+ object G {
2+ final class X
3+ final class Y
4+
5+ opaque type Foo = Nothing // or X & Y
6+ object Foo {
7+ def apply [F [_]](fa : F [X & Foo ]): F [Y & Foo ] = fa
8+ }
9+
10+ type Bar [A ] = A match {
11+ case X => String
12+ case Y => Int
13+ }
14+
15+ val a : Bar [X & Foo ] = " hello"
16+ val b : Bar [Y & Foo ] = 1 // error
17+
18+ def main (args : Array [String ]): Unit = {
19+ val a : Bar [X & Foo ] = " hello"
20+ val i : Bar [Y & Foo ] = Foo .apply[Bar ](a)
21+ val b : Int = i // error
22+ println(b + 1 )
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ object G {
2+ trait Wizzle [L <: Int with Singleton ] {
3+ type Bar [A ] = A match {
4+ case 0 => String
5+ case L => Int
6+ }
7+
8+ def left (fa : String ): Bar [0 ] = fa
9+ def right (fa : Bar [L ]): Int = fa // error
10+
11+ def center [F [_]](fa : F [0 ]): F [L ]
12+
13+ def run : String => Int = left andThen center[Bar ] andThen right
14+ }
15+
16+ class Wozzle extends Wizzle [0 ] {
17+ def center [F [_]](fa : F [0 ]): F [0 ] = fa
18+ }
19+
20+ def main (args : Array [String ]): Unit = {
21+ val coerce : String => Int = (new Wozzle ).run
22+ println(coerce(" hello" ) + 1 )
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ object G {
2+ trait Wizzle {
3+ type X <: Int with Singleton
4+ type Y <: Int with Singleton
5+
6+ type Bar [A ] = A match {
7+ case X => String
8+ case Y => Int
9+ }
10+
11+ def left (fa : String ): Bar [X ] = fa
12+ def center [F [_]](fa : F [X ]): F [Y ]
13+ def right (fa : Bar [Y ]): Int = fa // error
14+
15+ def run : String => Int = left andThen center[Bar ] andThen right
16+ }
17+
18+ class Wozzle extends Wizzle {
19+ type X = 0
20+ type Y = 0
21+ def center [F [_]](fa : F [X ]): F [Y ] = fa
22+ }
23+
24+ def main (args : Array [String ]): Unit = {
25+ val coerce : String => Int = (new Wozzle ).run
26+ println(coerce(" hello" ) + 1 )
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ object G {
2+ type Void <: Nothing
3+ trait Wizzle {
4+ type Razzle [+ X >: Void ]
5+ type X = 0
6+ type Y = 1
7+
8+ type Bar [A ] = A match {
9+ case Razzle [X ] => String
10+ case Razzle [Y ] => Int
11+ }
12+
13+ def left (fa : String ): Bar [Razzle [X ]] = fa
14+ def center [F [_]](fa : F [Razzle [X ]]): F [Razzle [Y ]]
15+ def right (fa : Bar [Razzle [Y ]]): Int = fa // error
16+
17+ def run : String => Int = left andThen center[Bar ] andThen right
18+ }
19+
20+ class Wozzle extends Wizzle {
21+ type Razzle [+ X >: Void ] = Int
22+ def center [F [_]](fa : F [Razzle [X ]]): F [Razzle [Y ]] = fa
23+ }
24+
25+ def main (args : Array [String ]): Unit = {
26+ val coerce : String => Int = (new Wozzle ).run
27+ println(coerce(" hello" ) + 1 )
28+ }
29+ }
Original file line number Diff line number Diff line change @@ -46,3 +46,28 @@ object Test2 {
4646 def right (fa : Bar [L ]): Int = fa // error
4747 }
4848}
49+
50+
51+ object Test3 {
52+ type Bar [A ] = A match {
53+ case X => String
54+ case Y => Int
55+ }
56+
57+ trait XX {
58+ type Foo
59+
60+ val a : Bar [X & Foo ] = " hello"
61+ val b : Bar [Y & Foo ] = 1 // error
62+
63+ def apply (fa : Bar [X & Foo ]): Bar [Y & Foo ]
64+
65+ def boom : Int = apply(a) // error
66+ }
67+
68+ trait YY extends XX {
69+ type Foo = X & Y
70+
71+ def apply (fa : Bar [X & Foo ]): Bar [Y & Foo ] = fa
72+ }
73+ }
You can’t perform that action at this time.
0 commit comments