blob: 76dd70538022d205a45f1b867c73b31df0e9fd09 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
class Foo {
class Line {
case class Cell[T](var x: T)
def f[T](x: Any): Cell[t1] for_some { type t1 } = x match { case y: Cell[t] => y }
var x: Cell[T] for_some { type T } = new Cell(1)
println({ x = new Cell("abc"); x })
}
}
trait Counter[T] {
def newCounter: T
def get(i: T): Int
def inc(i: T): T
}
case class C[T](x: T)
object LUB {
def x = C(1)
def y = C("abc")
var coinflip: boolean = _
def z = if (coinflip) x else y
def zz: C[_1] for_some { type _1 >: Int with java.lang.String } = z
}
object Test extends Application {
def foo(x : Counter[T] { def name : String } for_some { type T }) = x match {
case ctr: Counter[t] =>
val c = ctr.newCounter
println(ctr.name+" "+ctr.get(ctr.inc(ctr.inc(c))))
case _ =>
}
var ex: Counter[T] for_some { type T } = _
ex = ci
ex = cf
val ci = new Counter[Int] {
def newCounter = 0
def get(i: Int) = i
def inc(i: Int) = i+1
def name = "Int"
}
val cf = new Counter[Float] {
def newCounter = 0
def get(i: Float) = i.intValue
def inc(i: Float) = i+1
def name = "Float"
}
foo(ci)
foo(cf)
val foo = new Foo
new foo.Line
}
|