summaryrefslogtreecommitdiff
path: root/dhall/src/core/var.rs
diff options
context:
space:
mode:
authorNadrieril2019-05-07 18:38:54 +0200
committerNadrieril2019-05-07 18:38:54 +0200
commitb3f00a827bcdd0fe406ccf8913cc5fb7cd6e0f2f (patch)
tree18d8326069fe94bcb03177c3375fcf453a370759 /dhall/src/core/var.rs
parent8cb3046e0920bf24d66c578b1a2b184c741b73fe (diff)
Promote shift and subst_shift to traits
Diffstat (limited to '')
-rw-r--r--dhall/src/core/var.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/dhall/src/core/var.rs b/dhall/src/core/var.rs
index e431fc2..21bc06b 100644
--- a/dhall/src/core/var.rs
+++ b/dhall/src/core/var.rs
@@ -14,6 +14,14 @@ pub(crate) struct AlphaVar {
#[derive(Debug, Clone, Eq)]
pub(crate) struct AlphaLabel(Label);
+pub(crate) trait Shift {
+ fn shift(&self, delta: isize, var: &AlphaVar) -> Self;
+}
+
+pub(crate) trait Subst<T>: Shift {
+ fn subst_shift(&self, var: &AlphaVar, val: &T) -> Self;
+}
+
impl AlphaVar {
pub(crate) fn to_var(&self, alpha: bool) -> V<Label> {
match (alpha, &self.alpha) {
@@ -27,15 +35,6 @@ impl AlphaVar {
alpha: None,
}
}
- pub(crate) fn shift(&self, delta: isize, var: &AlphaVar) -> Self {
- AlphaVar {
- normal: self.normal.shift(delta, &var.normal),
- alpha: match (&self.alpha, &var.alpha) {
- (Some(x), Some(v)) => Some(x.shift(delta, v)),
- _ => None,
- },
- }
- }
}
impl AlphaLabel {
@@ -51,6 +50,18 @@ impl AlphaLabel {
}
}
+impl Shift for AlphaVar {
+ fn shift(&self, delta: isize, var: &AlphaVar) -> Self {
+ AlphaVar {
+ normal: self.normal.shift(delta, &var.normal),
+ alpha: match (&self.alpha, &var.alpha) {
+ (Some(x), Some(v)) => Some(x.shift(delta, v)),
+ _ => None,
+ },
+ }
+ }
+}
+
impl std::cmp::PartialEq for AlphaVar {
fn eq(&self, other: &Self) -> bool {
match (&self.alpha, &other.alpha) {