summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-04-11 19:04:19 +0200
committerNadrieril2019-04-11 19:04:19 +0200
commita4ef23fd3e7a053def648dca05dfc9a043af9860 (patch)
treeb74c33df5699313380335aa3ef2e1dbd4af23c5a /dhall_core
parent61b2ac7fb35c2a8aca703d5a5f9a9a8f28def977 (diff)
Respect import boundaries
Closes #54
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/core.rs66
1 files changed, 46 insertions, 20 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs
index 1c41acc..d2ecf53 100644
--- a/dhall_core/src/core.rs
+++ b/dhall_core/src/core.rs
@@ -324,29 +324,18 @@ impl<S, A> Expr<S, A> {
}
}
-impl<S: Clone, A: Clone> Expr<S, Expr<S, A>> {
- pub fn squash_embed(&self) -> Expr<S, A> {
- match self {
- ExprF::Embed(e) => e.clone(),
- e => e.map_shallow(
- <Expr<S, Expr<S, A>>>::squash_embed,
- S::clone,
- |_| unreachable!(),
- Label::clone,
- ),
- }
- }
-}
-
-impl<S: Clone, A: Clone> Expr<S, SubExpr<S, A>> {
- pub fn squash_embed(&self) -> SubExpr<S, A> {
+impl<N: Clone, E> Expr<N, E> {
+ pub fn squash_embed<E2: Clone>(
+ &self,
+ f: &impl Fn(&E) -> SubExpr<N, E2>,
+ ) -> SubExpr<N, E2> {
match self.as_ref() {
- ExprF::Embed(e) => e.clone(),
+ ExprF::Embed(e) => f(e),
e => e
.map(
- |e| e.as_ref().squash_embed(),
- |_, e| e.as_ref().squash_embed(),
- S::clone,
+ |e| e.as_ref().squash_embed(f),
+ |_, e| e.as_ref().squash_embed(f),
+ N::clone,
|_| unreachable!(),
Label::clone,
)
@@ -675,6 +664,43 @@ impl<N, E> SubExpr<N, E> {
}
}
+impl<N: Clone> SubExpr<N, X> {
+ pub fn absurd<T>(&self) -> SubExpr<N, T> {
+ rc(self.as_ref().absurd_rec())
+ }
+}
+
+impl<N: Clone> Expr<N, X> {
+ // This is all very sad and I hope this can be avoided sometime
+ pub fn absurd_rec<T>(&self) -> Expr<N, T> {
+ self.map_ref(
+ |e| e.absurd(),
+ |_, e| e.absurd(),
+ |_| unreachable!(),
+ |_| unreachable!(),
+ Label::clone,
+ )
+ }
+}
+
+impl<SE, L, N, E> ExprF<SE, L, N, E>
+where
+ SE: Clone,
+ L: Clone + Ord,
+ N: Clone,
+{
+ // When we know there is no Embed
+ pub fn absurd<T>(&self) -> ExprF<SE, L, N, T> {
+ self.map_ref(
+ |e| e.clone(),
+ |_, e| e.clone(),
+ N::clone,
+ |_| unreachable!(),
+ L::clone,
+ )
+ }
+}
+
impl<N, E> Clone for SubExpr<N, E> {
fn clone(&self) -> Self {
SubExpr(Rc::clone(&self.0))