summaryrefslogtreecommitdiff
path: root/dhall_syntax/src/core.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dhall_syntax/src/core.rs')
-rw-r--r--dhall_syntax/src/core.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/dhall_syntax/src/core.rs b/dhall_syntax/src/core.rs
index c8a2425..389f037 100644
--- a/dhall_syntax/src/core.rs
+++ b/dhall_syntax/src/core.rs
@@ -60,7 +60,7 @@ pub enum Const {
/// The `Int` field is a DeBruijn index.
/// See dhall-lang/standard/semantics.md for details
#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct Var<Label>(pub Label, pub usize);
+pub struct Var<VarLabel>(pub VarLabel, pub usize);
// Definition order must match precedence order for
// pretty-printing to work correctly
@@ -529,6 +529,19 @@ impl<'a> From<&'a Label> for Var<Label> {
}
}
+/// Trait for things that capture a label used for variables.
+/// Allows normalization to be generic in whether to alpha-normalize or not.
+pub trait VarLabel: std::fmt::Display + Clone {
+ /// Is `self` the default variable (i.e. "_") ?
+ fn is_underscore_var(&self) -> bool;
+}
+
+impl VarLabel for Label {
+ fn is_underscore_var(&self) -> bool {
+ &String::from(self) == "_"
+ }
+}
+
/// `shift` is used by both normalization and type-checking to avoid variable
/// capture by shifting variable indices
/// See https://github.com/dhall-lang/dhall-lang/blob/master/standard/semantics.md#shift