blob: 80da2ec868b451219aa54ab0e522549405edbde1 (
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
|
class Inv[A](x: A)
object Inv {
def empty[A]: Inv[A] = new Inv(???)
}
class Inv2[A](x: A)
object Inv2 {
def empty[A]: Inv2[A] = new Inv2(???)
}
object Test {
def inv(cond: Boolean) =
if (cond)
new Inv(1)
else
Inv.empty
val x: Inv[Int] = inv(true)
def inv2(cond: Boolean) =
if (cond) {
if (cond)
new Inv(1)
else
Inv.empty
} else {
if (cond)
new Inv2(1)
else
Inv2.empty
}
val y: Inv[Int] | Inv2[Int] = inv2(true)
}
|