summaryrefslogtreecommitdiff
path: root/dhall_syntax/src/core.rs
diff options
context:
space:
mode:
authorNadrieril2019-05-07 16:01:24 +0200
committerNadrieril2019-05-07 16:01:24 +0200
commit726c281cdd3824fcfdde34fe8d01f95416f7808c (patch)
treea3a7b89348a1f63208b3912d45e0ecd6d3f344a3 /dhall_syntax/src/core.rs
parent1b8a67353a0167bdafd0b8cc03f5d83464f7af3d (diff)
Clean up some of the SubExpr type-changing methods
Diffstat (limited to 'dhall_syntax/src/core.rs')
-rw-r--r--dhall_syntax/src/core.rs40
1 files changed, 11 insertions, 29 deletions
diff --git a/dhall_syntax/src/core.rs b/dhall_syntax/src/core.rs
index 7cdda64..2b76b9a 100644
--- a/dhall_syntax/src/core.rs
+++ b/dhall_syntax/src/core.rs
@@ -343,15 +343,11 @@ impl<N, E> Expr<N, E> {
{
trivial_result(self.traverse_embed(|x| Ok(map_embed(x))))
}
+}
- pub fn squash_embed<E2>(
- &self,
- f: impl FnMut(&E) -> SubExpr<N, E2>,
- ) -> SubExpr<N, E2>
- where
- N: Clone,
- {
- trivial_result(self.visit(&mut visitor::SquashEmbedVisitor(f)))
+impl Expr<X, X> {
+ pub fn absurd<N, E>(&self) -> Expr<N, E> {
+ self.visit(&mut visitor::AbsurdVisitor)
}
}
@@ -361,12 +357,6 @@ impl<E: Clone> Expr<X, E> {
}
}
-impl<N: Clone> Expr<N, X> {
- pub fn embed_absurd<E>(&self) -> Expr<N, E> {
- self.visit(&mut visitor::EmbedAbsurdVisitor)
- }
-}
-
impl<N, E> SubExpr<N, E> {
pub fn as_ref(&self) -> &Expr<N, E> {
&self.0.as_ref().0
@@ -380,17 +370,6 @@ impl<N, E> SubExpr<N, E> {
SubExpr(Rc::new((x, None)))
}
- pub fn unnote(&self) -> SubExpr<X, E>
- where
- E: Clone,
- {
- SubExpr::from_expr_no_note(
- self.as_ref().visit(&mut visitor::UnNoteVisitor),
- )
- }
-}
-
-impl<N: Clone, E> SubExpr<N, E> {
pub fn rewrap<E2>(&self, x: Expr<N, E2>) -> SubExpr<N, E2>
where
N: Clone,
@@ -422,7 +401,10 @@ impl<N: Clone, E> SubExpr<N, E> {
&'a self,
map_expr: impl FnMut(&'a Self) -> Self,
map_under_binder: impl FnMut(&'a Label, &'a Self) -> Self,
- ) -> Self {
+ ) -> Self
+ where
+ N: Clone,
+ {
match self.as_ref() {
ExprF::Embed(_) => SubExpr::clone(self),
// This calls ExprF::map_ref
@@ -436,9 +418,9 @@ impl<N: Clone, E> SubExpr<N, E> {
}
}
-impl<N: Clone> SubExpr<N, X> {
- pub fn embed_absurd<T>(&self) -> SubExpr<N, T> {
- self.rewrap(self.as_ref().embed_absurd())
+impl SubExpr<X, X> {
+ pub fn absurd<N: Clone, T>(&self) -> SubExpr<N, T> {
+ SubExpr::from_expr_no_note(self.as_ref().absurd())
}
}