From 30397d3638b47557333935b24cfbfced69e40e9d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 18 Apr 2019 12:06:36 +0200 Subject: Merge impl blocks --- dhall_core/src/core.rs | 210 ++++++++++++++++++++++++------------------------- 1 file changed, 104 insertions(+), 106 deletions(-) diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs index a233d67..1c1aa23 100644 --- a/dhall_core/src/core.rs +++ b/dhall_core/src/core.rs @@ -211,85 +211,7 @@ impl ExprF { { v.visit(self) } -} - -impl Expr { - pub fn map_shallow( - &self, - map_expr: F1, - map_note: F2, - map_embed: F3, - map_label: F4, - ) -> Expr - where - E: Clone, - N2: Clone, - N: Clone, - F1: Fn(&Self) -> Expr, - F2: Fn(&N) -> N2, - F3: Fn(&E) -> E2, - F4: Fn(&Label) -> Label, - { - self.map_ref( - |x| rc(map_expr(x.as_ref())), - map_note, - map_embed, - map_label, - ) - } - pub fn map_embed(&self, map_embed: &F) -> Expr - where - E: Clone, - N: Clone, - F: Fn(&E) -> E2, - { - let recurse = - |e: &Expr| -> Expr { e.map_embed(map_embed) }; - self.map_shallow(recurse, N::clone, map_embed, Label::clone) - } - - pub fn traverse_embed( - &self, - map_embed: F, - ) -> Result, Err> - where - N: Clone, - E2: Clone, - F: FnMut(&E) -> Result, - { - self.visit(&mut visitor::TraverseEmbedVisitor(map_embed)) - } - - pub fn map_label(&self, map_label: &F) -> Self - where - E: Clone, - N: Clone, - F: Fn(&Label) -> Label, - { - let recurse = |e: &Self| -> Self { e.map_label(map_label) }; - self.map_shallow(recurse, N::clone, E::clone, map_label) - } - - pub fn roll(&self) -> SubExpr - where - N: Clone, - E: Clone, - { - rc(ExprF::clone(self)) - } -} - -impl Expr { - pub fn squash_embed( - &self, - f: impl FnMut(&E) -> SubExpr, - ) -> SubExpr { - rc(self.visit(&mut visitor::SquashEmbedVisitor(f))) - } -} - -impl ExprF { pub fn traverse_ref_with_special_handling_of_binders< 'a, SE2, @@ -439,6 +361,100 @@ impl ExprF { } } +impl Expr { + pub fn map_shallow( + &self, + map_expr: F1, + map_note: F2, + map_embed: F3, + map_label: F4, + ) -> Expr + where + E: Clone, + N2: Clone, + N: Clone, + F1: Fn(&Self) -> Expr, + F2: Fn(&N) -> N2, + F3: Fn(&E) -> E2, + F4: Fn(&Label) -> Label, + { + self.map_ref( + |x| rc(map_expr(x.as_ref())), + map_note, + map_embed, + map_label, + ) + } + + pub fn map_embed(&self, map_embed: &F) -> Expr + where + E: Clone, + N: Clone, + F: Fn(&E) -> E2, + { + let recurse = + |e: &Expr| -> Expr { e.map_embed(map_embed) }; + self.map_shallow(recurse, N::clone, map_embed, Label::clone) + } + + pub fn traverse_embed( + &self, + map_embed: F, + ) -> Result, Err> + where + N: Clone, + E2: Clone, + F: FnMut(&E) -> Result, + { + self.visit(&mut visitor::TraverseEmbedVisitor(map_embed)) + } + + pub fn map_label(&self, map_label: &F) -> Self + where + E: Clone, + N: Clone, + F: Fn(&Label) -> Label, + { + let recurse = |e: &Self| -> Self { e.map_label(map_label) }; + self.map_shallow(recurse, N::clone, E::clone, map_label) + } + + pub fn roll(&self) -> SubExpr + where + N: Clone, + E: Clone, + { + rc(ExprF::clone(self)) + } + + pub fn squash_embed( + &self, + f: impl FnMut(&E) -> SubExpr, + ) -> SubExpr + where + N: Clone, + E2: Clone, + { + rc(self.visit(&mut visitor::SquashEmbedVisitor(f))) + } +} + +impl Expr { + pub fn note_absurd(&self) -> Expr { + self.visit(&mut visitor::NoteAbsurdVisitor) + } +} + +impl Expr { + // Deprecated, use embed_absurd instead + pub fn absurd_rec(&self) -> Expr { + self.embed_absurd() + } + pub fn embed_absurd(&self) -> Expr { + self.visit(&mut visitor::EmbedAbsurdVisitor) + } +} + impl SubExpr { pub fn as_ref(&self) -> &Expr { self.0.as_ref() @@ -479,12 +495,22 @@ impl SubExpr { { ExprF::clone(self.as_ref()) } + + pub fn unnote(&self) -> SubExpr + where + E: Clone, + { + rc(self.as_ref().visit(&mut visitor::UnNoteVisitor)) + } } impl SubExpr { pub fn absurd(&self) -> SubExpr { rc(self.as_ref().absurd_rec()) } + pub fn embed_absurd(&self) -> SubExpr { + rc(self.as_ref().embed_absurd()) + } } impl SubExpr { @@ -493,34 +519,6 @@ impl SubExpr { } } -impl Expr { - pub fn note_absurd(&self) -> Expr { - self.visit(&mut visitor::NoteAbsurdVisitor) - } -} - -impl SubExpr { - pub fn unnote(&self) -> SubExpr { - rc(self.as_ref().visit(&mut visitor::UnNoteVisitor)) - } -} - -impl Expr { - // Deprecated, use embed_absurd instead - pub fn absurd_rec(&self) -> Expr { - self.embed_absurd() - } - pub fn embed_absurd(&self) -> Expr { - self.visit(&mut visitor::EmbedAbsurdVisitor) - } -} - -impl SubExpr { - pub fn embed_absurd(&self) -> SubExpr { - rc(self.as_ref().embed_absurd()) - } -} - impl Clone for SubExpr { fn clone(&self) -> Self { SubExpr(Rc::clone(&self.0)) -- cgit v1.2.3