More infra around unify

This commit is contained in:
greg 2019-02-10 06:53:11 -08:00
parent 5a70784346
commit afd9aa52c5

View File

@ -22,13 +22,13 @@ impl TypeError {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum Type {
Const(TypeConst),
Arrow(Box<Type>, Box<Type>)
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum TypeConst {
Unit,
Nat,
@ -150,6 +150,10 @@ impl<'a> TypeContext<'a> {
}
}
fn get_type_from_name(&self, name: &TypeIdentifier) -> InferResult<Type> {
Ok(Type::Const(TypeConst::Unit))
}
pub fn typecheck(&mut self, ast: &AST) -> Result<String, String> {
let mut returned_type = Type::Const(TypeConst::Unit);
for statement in ast.0.iter() {
@ -171,9 +175,11 @@ impl<'a> TypeContext<'a> {
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
match expr {
Expression(expr_type, Some(_anno)) => {
Expression(expr_type, Some(anno)) => {
//TODO here
self.typecheck_expr_type(expr_type)
let t1 = self.typecheck_expr_type(expr_type)?;
let t2 = self.get_type_from_name(anno)?;
self.unify(t2, t1)
},
Expression(expr_type, None) => self.typecheck_expr_type(expr_type)
}
@ -191,7 +197,8 @@ impl<'a> TypeContext<'a> {
}
fn unify(&mut self, t1: &Type, t2: &Type) -> InferResult<Type> {
unimplemented!()
fn unify(&mut self, t1: Type, t2: Type) -> InferResult<Type> {
println!("Unify ain't done yo");
Ok(t1)
}
}