junkcode
Check-in [cc63b07abf]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove nested data structure.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:cc63b07abff211cd522b9b5de43e99a3f4715a5dd607c793e034ad6fee3842bc
User & Date: jaccarmac 2017-12-31 06:42:06
Context
2017-12-31
06:59
Get working example going. check-in: 831facee98 user: jaccarmac tags: trunk
06:42
Remove nested data structure. check-in: cc63b07abf user: jaccarmac tags: trunk
06:40
Try to update API project. check-in: 03a16ca781 user: jaccarmac tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to polymorphic-recursion/rust/src/main.rs.

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
        match self {
            IntList::Nil => 0,
            IntList::Cons(_, t) => 1 + t.length(),
        }
    }
}

enum Nested<T> {
    Epsilon,
    Cons(T, Box<Nested<Vec<T>>>),
}

impl<T> Nested<T> {
    pub fn length(self) -> i64 {
        match self {
            Nested::Epsilon => 0,
            Nested::Cons(_, t) => 1 + t.length(),
        }
    }
}

fn main() {
    let int_list = IntList::Cons(
        0,
        Box::new(IntList::Cons(
            1,
            Box::new(IntList::Cons(
                2,
                Box::new(IntList::Cons(3, Box::new(IntList::Nil))),
            )),
        )),
    );
    println!("{}", int_list.length());

    let nested = Nested::Cons(
        0,
        Box::new(Nested::Cons(vec![1, 2, 3], Box::new(Nested::Epsilon))),
    );
    println!("{}", nested.length());
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<












|
<
<
<
<
<
<
8
9
10
11
12
13
14














15
16
17
18
19
20
21
22
23
24
25
26
27






        match self {
            IntList::Nil => 0,
            IntList::Cons(_, t) => 1 + t.length(),
        }
    }
}















fn main() {
    let int_list = IntList::Cons(
        0,
        Box::new(IntList::Cons(
            1,
            Box::new(IntList::Cons(
                2,
                Box::new(IntList::Cons(3, Box::new(IntList::Nil))),
            )),
        )),
    );
    println!("{}", int_list.length());
}