use super::{TypeScheme, TypeConstructor};
use super::type_classes::TypeClassInstance;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct TypeEnv {
pub bindings: HashMap<String, TypeScheme>,
pub instances: HashMap<String, Vec<TypeClassInstance>>,
pub constructors: HashMap<String, TypeConstructor>,
}
impl TypeEnv {
pub fn new() -> Self {
Self {
bindings: HashMap::new(),
instances: HashMap::new(),
constructors: HashMap::new(),
}
}
pub fn lookup(&self, name: &str) -> Option<&TypeScheme> {
self.bindings.get(name)
}
pub fn bind(&mut self, name: String, scheme: TypeScheme) {
self.bindings.insert(name, scheme);
}
pub fn extend(&self, bindings: HashMap<String, TypeScheme>) -> Self {
let mut new_env = self.clone();
new_env.bindings.extend(bindings);
new_env
}
}
impl Default for TypeEnv {
fn default() -> Self {
Self::new()
}
}