[no description]
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#![allow(non_snake_case)]
use super::*;
include!(concat!(env!("OUT_DIR"), "/impl_td.rs"));
include!(concat!(env!("OUT_DIR"), "/impl_rv.rs"));
include!(concat!(env!("OUT_DIR"), "/impl_pk.rs"));

macro_rules! generate {(
    $($Hd:tt $($T:tt)*)?
) => (
    $(generate! { $($T)* })?
    do_impl! { [$] $($($T)* [$] $Hd)? }
)}
// impl Reverse for () {
//     type Reversed = ();

//     fn reverse(self) -> Self::Reversed {
//         ()
//     }
// }
impl Tupl for () {
    const LEN: usize = 0;
    type Head = !;
    type Last = !;
    type Tail = ();
    type Init = ();
    type Inner = ();

    fn uncons(self) -> (Self::Head, Self::Tail) {
        todo!()
    }
    fn unsnoc(self) -> (Self::Init, Self::Last) {
        todo!()
    }
    fn fcons(head: Self::Head, _: Self::Inner, _: Self::Last) -> Self {
        match head {}
    }
    fn cons(head: Self::Head, _: Self::Tail) -> Self {
        match head {}
    }
    fn snoc(_: Self::Init, last: Self::Last) -> Self {
        match last {}
    }
}
impl<T> Tupl for (T,) {
    const LEN: usize = 1;
    type Head = T;
    type Last = T;
    type Tail = ();
    type Init = ();
    type Inner = ();

    fn uncons(self) -> (Self::Head, Self::Tail) {
        unimplemented!("dont call base case.")
    }

    fn unsnoc(self) -> (Self::Init, Self::Last) {
        unimplemented!("dont call base case.")
    }

    fn cons(_: Self::Head, _: Self::Tail) -> Self {
        unimplemented!("dont call base case.")
    }
    fn snoc(_: Self::Init, _: Self::Last) -> Self {
        unimplemented!("dont call base case.")
    }
    fn fcons(_: Self::Head, _: Self::Inner, _: Self::Last) -> Self {
        unimplemented!("dont call base case.")
    }
}

macro_rules! do_impl {
([$_:tt]) => {};
([$_:tt] [$] $i:tt) => {};
// ([$_:tt] $i:ident [$] $x:tt) => {};
(
    [$_:tt] // `$` sigil
    $hd:tt $($i:ident)* [$] $tl:tt
) => (
    // impl<T> Seal for ($($i, )*) {}
    impl<$($i,)* Α> Cons<Α> for ($($i,)*) {
        type Cons = (Α, $($i,)*);
        type Snoc = ($($i,)* Α,);
    }

    #[allow(non_snake_case)]
    impl<$hd, $($i,)* $tl> Tupl for ($hd, $($i,)* $tl) {
        const LEN: usize = 0 $(+ { stringify!($i); 1 } )*;
        type Head = $hd;
        type Last = $tl;
        type Tail = ($($i,)* $tl,);
        type Init = ($hd, $($i,)*);
        type Inner = ($($i,)*);
        fn cons(head: Self::Head, ($($i,)* $tl,): Self::Tail) -> Self {
           (head, $($i,)* $tl,)
        }
        fn snoc(($hd, $($i,)*): Self::Init, last: Self::Last) -> Self {
            ($hd, $($i,)* last)
        }
        fn fcons(head: Self::Head, ($($i,)*): Self::Inner, last: Self::Last) -> Self {
            (head, $($i,)* last)
        }
        fn uncons(self) -> (Self::Head, Self::Tail) {
            let ($hd, $($i,)* $tl) = self;
            ($hd, ($($i,)* $tl,))
        }
        fn unsnoc(self) -> (Self::Init, Self::Last) {
            let ($hd, $($i,)* $tl) = self;
            (($hd, $($i,)*), $tl)
        }
        // fn array(self) -> [T; 0 $(+ { stringify!($i); 1 } )*] {
        //     with_vars! {
        //         [acc: ]
        //         [to_munch: $($i)*]
        //         |$_ x| {
        //             let ($_($_ x, )*) = self;
        //             [$_($_ x, )*]
        //         }
        //     }
        // }
        // fn tuple(x: [T;  0 $(+ { stringify!($i); 1 } )*]) -> ($($i, )*) {
        //     with_vars! {
        //         [acc: ]
        //         [to_munch: $($i)*]
        //         |$_ x| {
        //             let [$_($x, )*] = x;
        //             ($_($x, )*)
        //         }
        //     }
        // }
    }
);
}

generate!(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);

impl<T, U: Cons<T>> Push<T> for U {
    type Result = U::Snoc;

    fn push(self, other: T) -> Self::Result {
        crate::snoc(self, other)
    }
}

impl<T, U: Cons<T>> With<U> for T {
    type Result = U::Cons;

    fn with(self, other: U) -> Self::Result {
        crate::cons(self, other)
    }
}