diff options
author | NanoTech | 2016-12-08 21:24:26 +0000 |
---|---|---|
committer | NanoTech | 2017-03-10 23:48:28 -0600 |
commit | 1619be740b2a050fd172523226002e9ea141e38b (patch) | |
tree | 9596ac676310aaf6aed59c035ede2267a30a2fde /src | |
parent | 54064666084d6dfa3eaecb7ba51c09c28b8cf987 (diff) |
subst: Don't need to match on the left Expr
Diffstat (limited to 'src')
-rw-r--r-- | src/core.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/core.rs b/src/core.rs index 3171a8c..e9f185c 100644 --- a/src/core.rs +++ b/src/core.rs @@ -508,41 +508,41 @@ shift _ _ (Embed p) = Embed p /// subst x C B ~ B[x := C] /// ``` /// -pub fn subst<'i, S, T, A>(v: V<'i>, a: &Expr<'i, S, A>, b: &Expr<'i, T, A>) -> Expr<'i, S, A> +pub fn subst<'i, S, T, A>(v: V<'i>, e: &Expr<'i, S, A>, b: &Expr<'i, T, A>) -> Expr<'i, S, A> where S: Clone + ::std::fmt::Debug, T: Clone + ::std::fmt::Debug, - A: Clone + ::std::fmt::Debug, + A: Clone + ::std::fmt::Debug { use Expr::*; let V(x, n) = v; - match (a, b) { - (_, &Const(a)) => Const(a), - (e, &Lam(y, ref tA, ref b)) => { + match b { + &Const(a) => Const(a), + &Lam(y, ref tA, ref b) => { let n2 = if x == y { n + 1 } else { n }; let b2 = subst(V(x, n2), &shift(1, V(y, 0), &e), b); let tA2 = subst(V(x, n), &e, tA); Lam(y, bx(tA2), bx(b2)) } - (e, &Pi(y, ref tA, ref tB)) => { + &Pi(y, ref tA, ref tB) => { let n2 = if x == y { n + 1 } else { n }; let tB2 = subst(V(x, n2), &shift(1, V(y, 0), &e), tB); let tA2 = subst(V(x, n), &e, tA); pi(y, tA2, tB2) } - (e, &App(ref f, ref a)) => { + &App(ref f, ref a) => { let f2 = subst(v, e, f); let a2 = subst(v, e, a); app(f2, a2) } - (e, &Var(v2)) => if v == v2 { e.clone() } else { Var(v2) }, - (e, &ListLit(ref a, ref b)) => { + &Var(v2) => if v == v2 { e.clone() } else { Var(v2) }, + &ListLit(ref a, ref b) => { let a2 = subst(v, e, a); let b2 = b.iter().map(|be| subst(v, e, be)).collect(); ListLit(bx(a2), b2) } - (_, &BuiltinType(t)) => BuiltinType(t), - (_, &BuiltinValue(v)) => BuiltinValue(v), - (a, b) => panic!("Unimplemented subst case: {:?}", (v, a, b)), + &BuiltinType(t) => BuiltinType(t), + &BuiltinValue(v) => BuiltinValue(v), + b => panic!("Unimplemented subst case: {:?}", (v, e, b)), } } |