use std::collections::HashMap; use crate::error::TypeError; use crate::semantics::core::value::Value; use crate::semantics::core::value::ValueKind; use crate::semantics::core::var::{AlphaVar, Shift, Subst}; use crate::syntax::{Label, V}; #[derive(Debug, Clone)] enum CtxItem { Kept(AlphaVar, Value), Replaced(Value), } #[derive(Debug, Clone)] pub(crate) struct TypecheckContext { ctx: Vec<(Label, CtxItem)>, } impl TypecheckContext { pub fn new() -> Self { TypecheckContext { ctx: Vec::new() } } fn with_vec(&self, vec: Vec<(Label, CtxItem)>) -> Self { TypecheckContext { ctx: vec } } pub fn insert_type(&self, x: &Label, t: Value) -> Self { let mut vec = self.ctx.clone(); vec.push((x.clone(), CtxItem::Kept(x.into(), t.under_binder(x)))); self.with_vec(vec) } pub fn insert_value(&self, x: &Label, e: Value) -> Result { let mut vec = self.ctx.clone(); vec.push((x.clone(), CtxItem::Replaced(e))); Ok(self.with_vec(vec)) } pub fn lookup(&self, var: &V