diff options
Diffstat (limited to 'src/reduce.c')
-rw-r--r-- | src/reduce.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/reduce.c b/src/reduce.c index 38baf06..2ae6e8e 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -14,9 +14,9 @@ static struct term *substitute(struct term *term, struct term *substitution, { if (term->type == VAR) { if (term->u.var.index == level) { - term_deref_head(term); return substitution; } else { + term_refer_head(term, substitution->depth); return term; } } else if (term->type == ABS) { @@ -27,6 +27,7 @@ static struct term *substitute(struct term *term, struct term *substitution, return term; // nothing changed struct term *rehashed = term_rehash_abs(term, new); term_rehash_parents(rehashed); + term_deref_head(term->u.abs.term); return rehashed; } else if (term->type == APP) { hash_t previous_lhs = term->u.app.lhs->hash; @@ -48,12 +49,12 @@ static struct term *substitute(struct term *term, struct term *substitution, // ([X] Y) -> X/Y struct term *reduce(struct term *term) { - if (term->type != APP || term->u.app.lhs->type != ABS) + if (!term_is_beta_redex(term)) fatal("can't reduce non-beta-redex %d\n", term->type); - map_delete(term->u.app.lhs->parents, term); - map_delete(term->u.app.rhs->parents, term); + /* map_delete(term->u.app.lhs->parents, term); */ + /* map_delete(term->u.app.rhs->parents, term); */ struct term *reduced = substitute(term->u.app.lhs, term->u.app.rhs, -1); - term_deref_head(term); + /* term_deref_head(term); */ return reduced; } |