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
pub mod auto;
pub mod cons;
pub mod polar;

mod biunify;
mod subsume;
#[cfg(test)]
mod tests;

pub use self::biunify::{Error as BiunifyError, Result as BiunifyResult};
pub use self::cons::{Constructor, ConstructorSet, Label};

use std::ops;

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum Polarity {
    Neg = -1,
    Pos = 1,
}

impl Polarity {
    pub(crate) fn flip<T>(self, a: T, b: T) -> (T, T) {
        match self {
            Polarity::Pos => (a, b),
            Polarity::Neg => (b, a),
        }
    }
}

impl ops::Neg for Polarity {
    type Output = Self;

    fn neg(self) -> Self {
        match self {
            Polarity::Neg => Polarity::Pos,
            Polarity::Pos => Polarity::Neg,
        }
    }
}

impl ops::Mul for Polarity {
    type Output = Self;

    fn mul(self, other: Self) -> Self {
        match self {
            Polarity::Neg => -other,
            Polarity::Pos => other,
        }
    }
}