Skip to content

Commit

Permalink
[ bind as ] Move logic to util function
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Dec 4, 2019
1 parent 9d27994 commit f30ee71
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/check/rules/clause/mod.rs
Expand Up @@ -13,11 +13,17 @@ mod lhs;
mod state;

/// Bind as patterns
pub fn bind_as_pats<T>(mut tcs: TCS, asb: Vec<AsBind>, f: impl FnOnce(TCS) -> T) -> T {
pub fn bind_as_pats<T>(mut tcs: TCS, asb: Vec<AsBind>, f: impl FnOnce(TCS) -> TCMS<T>) -> TCMS<T> {
let to_pop = asb.len();
for bind in asb {
tcs.gamma.push(bind.into());
}
f(tcs)
let (thing, mut tcs) = f(tcs)?;
for _ in 0..=to_pop {
let len = tcs.gamma.len();
tcs.gamma.remove(len - 1);
}
Ok((thing, tcs))
}

/// Checking an abstract clause.
Expand All @@ -31,7 +37,6 @@ pub fn clause(tcs: TCS, cls: AbsClause, against: Term) -> TCMS<Clause> {
let ty = lhs.ty;
let patterns = lhs.pats;
let has_absurd = lhs.has_absurd;
let to_pop = lhs.as_binds.len();
bind_as_pats(tcs, lhs.as_binds, |mut tcs| {
let body = if has_absurd {
None
Expand All @@ -41,10 +46,6 @@ pub fn clause(tcs: TCS, cls: AbsClause, against: Term) -> TCMS<Clause> {
tcs = new_tcs;
Some(term.ast)
};
for _ in 0..=to_pop {
let len = tcs.gamma.len();
tcs.gamma.remove(len - 1);
}
let clause = Clause {
pat_tele,
patterns,
Expand Down

0 comments on commit f30ee71

Please sign in to comment.