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