ok kinda works?

This commit is contained in:
Michael Zhang 2023-11-30 01:30:04 -06:00
parent 4ff88c0ca9
commit 9b897194ca
2 changed files with 11 additions and 8 deletions

View file

@ -203,26 +203,25 @@ pub fn synthesize(ctx: &Context, term: &Term) -> Result<(Type, Context)> {
let ex_b_2 = ex_b.transform_with_visitor(&V(1, aug_ctx.size()))?; let ex_b_2 = ex_b.transform_with_visitor(&V(1, aug_ctx.size()))?;
let e_2 = e.transform_with_visitor(&V(0, aug_ctx.size()))?; let e_2 = e.transform_with_visitor(&V(0, aug_ctx.size()))?;
println!("---");
let wtf_ctx = typecheck(&aug_ctx, &e_2, &ex_b_2)?; let wtf_ctx = typecheck(&aug_ctx, &e_2, &ex_b_2)?;
let (before_marker, after_marker) = wtf_ctx.split_at(&marker_idx); let (before_marker, after_marker) = wtf_ctx.split_at(&marker_idx);
// Bump the levels down since we're splitting teh array // Bump the levels down since we're splitting teh array
struct V2(usize); struct V2(usize, usize);
impl Visitor for V2 { impl Visitor for V2 {
fn visit_index(&self, index: &mut ContextIndex) -> Result<()> { fn visit_index(&self, index: &mut ContextIndex) -> Result<()> {
index.debruijn_level -= 1; index.debruijn_level -= self.0;
index.debruijn_index = self.0 - 1 - index.debruijn_level; index.debruijn_index = self.1 - 1 - index.debruijn_level;
Ok(()) Ok(())
} }
} }
let after_marker = let after_marker =
after_marker.transform_with_visitor(&V2(after_marker.size()))?; after_marker.transform_with_visitor(&V2(0, after_marker.size()))?;
let tau = Type::Arrow(Box::new(ex_a_2), Box::new(ex_b)); let tau = Type::Arrow(Box::new(ex_a_2), Box::new(ex_b));
println!("pre-tau: {tau:?} (in {after_marker:?})");
let tau = app_ctx(&after_marker, &tau)?; let tau = app_ctx(&after_marker, &tau)?;
let tau = tau.transform_with_visitor(&V2(1, after_marker.size()))?;
// let (final_ctx, gen_idx) = // let (final_ctx, gen_idx) =
// before_marker.add(ContextEntry::ExistentialVar); // before_marker.add(ContextEntry::ExistentialVar);

View file

@ -232,7 +232,11 @@ impl Type {
Type::Existential(index) Type::Existential(index)
} }
Type::Polytype(_) => todo!(), Type::Polytype(_) => todo!(),
Type::Arrow(_, _) => todo!(), Type::Arrow(a, b) => {
let a = a.transform_with_visitor(visitor)?;
let b = b.transform_with_visitor(visitor)?;
Type::Arrow(Box::new(a), Box::new(b))
}
_ => ty, _ => ty,
}; };
visitor.visit_type_after(&mut ty)?; visitor.visit_type_after(&mut ty)?;
@ -348,7 +352,7 @@ pub struct Context {
impl fmt::Debug for Context { impl fmt::Debug for Context {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.vector) write!(f, "Γ{:?}", self.vector)
} }
} }