-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtlist.rs
55 lines (48 loc) · 995 Bytes
/
tlist.rs
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
use crate::tcore::*;
use crate::tnum::*;
use tyrade_macro::tyrade;
tyrade! {
enum TList {
Nil,
Cons(Type, TList)
}
fn TListLen<L>() {
match L {
Nil => Z,
Cons(X, XS) => S(TListLen(XS))
}
}
fn TListNth<L, I>() {
match L {
Nil => (),
Cons(X, XS) => match I {
Z => X,
S(I2) => TListNth(XS, I2)
}
}
}
fn TListSkip<L, I>() {
match L {
Nil => Nil,
Cons(X, XS) => match I {
Z => L,
S(I2) => TListSkip(XS, I2)
}
}
}
fn TListMap<L, F>() {
match L {
Nil => Nil,
Cons(X, XS) => Cons(F(X), TListMap(XS, F))
}
}
}
#[test]
fn list_test() {
use crate::tbool::*;
use crate::test_utils::assert_type_eq;
assert_type_eq::<S<S<Z>>, TListLen<Cons<(), Cons<(), Nil>>>>();
assert_type_eq::<u64, TListNth<Cons<i32, Cons<u64, Nil>>, S<Z>>>();
assert_type_eq::<Cons<TFalse, Cons<TTrue, Nil>>, TListMap<Cons<S<Z>, Cons<Z, Nil>>, TIsZeroFamily>>(
);
}