blob: 038d2ff80665fc8b213c0c46f404f4e9f7f79b54 (
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
|
class Test {
def test = {
val l1 = null: Int #: String #: Boolean #: String #: HNil.type
type _2 = Succ[Succ[Zero.type]]
val t1: Boolean = null.asInstanceOf[ l1.type#Drop[_2]#Head ]
val t2: Boolean = null.asInstanceOf[ l1.type#Apply[_2] ]
}
}
sealed trait Nat {
type Fold[U, F[_ <: U] <: U, Z <: U] <: U
}
final object Zero extends Nat {
type Fold[U, F[_ <: U] <: U, Z <: U] = Z
}
final class Succ[N <: Nat] extends Nat {
type Fold[U, F[_ <: U] <: U, Z <: U] = F[N#Fold[U, F, Z]]
}
trait HList {
type Head
type Tail <: HList
type Drop[N <: Nat] = N#Fold[HList, ({ type L[X <: HList] = X#Tail })#L, this.type]
type Apply[N <: Nat] = Drop[N]#Head
}
class #: [H, T <: HList] extends HList { type Head = H; type Tail = T }
object HNil extends HList { type Head = Nothing; type Tail = Nothing }
|