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
#[derive(Clone, Debug)]
pub enum LiteralTypes {
    String,
    Int,
    Float,
    Bag(Vec<LiteralTypes>),          // List of types (heterogeneous)
    Vector(Vec<LiteralTypes>),       // List of coordinates types (heterogeneous)
    Array(usize, Box<LiteralTypes>), // Length, homogeneous type
}

impl PartialEq for LiteralTypes {
    fn eq(&self, other: &Self) -> bool {
        match self {
            LiteralTypes::String => match other {
                LiteralTypes::String => true,
                _ => false,
            },
            LiteralTypes::Int => match other {
                LiteralTypes::Int => true,
                _ => false,
            },
            LiteralTypes::Float => match other {
                LiteralTypes::Float => true,
                LiteralTypes::Int => true,
                _ => false,
            },
            LiteralTypes::Bag(_) => match other {
                LiteralTypes::Bag(_) => true,
                _ => false,
            },
            LiteralTypes::Vector(v) => match other {
                LiteralTypes::Vector(ov) => {
                    let n = v.len();
                    if n != ov.len() {
                        false
                    } else {
                        for i in 0..n {
                            if v[i] != ov[i] {
                                return false;
                            }
                        }
                        true
                    }
                }
                _ => false,
            },
            LiteralTypes::Array(n, t) => match other {
                LiteralTypes::Array(on, ot) => {
                    if on == n {
                        t == ot
                    } else {
                        false
                    }
                }
                _ => false,
            },
        }
    }
}