More infra around unify
This commit is contained in:
parent
5a70784346
commit
afd9aa52c5
@ -22,13 +22,13 @@ impl TypeError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
Const(TypeConst),
|
Const(TypeConst),
|
||||||
Arrow(Box<Type>, Box<Type>)
|
Arrow(Box<Type>, Box<Type>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TypeConst {
|
pub enum TypeConst {
|
||||||
Unit,
|
Unit,
|
||||||
Nat,
|
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> {
|
pub fn typecheck(&mut self, ast: &AST) -> Result<String, String> {
|
||||||
let mut returned_type = Type::Const(TypeConst::Unit);
|
let mut returned_type = Type::Const(TypeConst::Unit);
|
||||||
for statement in ast.0.iter() {
|
for statement in ast.0.iter() {
|
||||||
@ -171,9 +175,11 @@ impl<'a> TypeContext<'a> {
|
|||||||
|
|
||||||
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
|
fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<Type> {
|
||||||
match expr {
|
match expr {
|
||||||
Expression(expr_type, Some(_anno)) => {
|
Expression(expr_type, Some(anno)) => {
|
||||||
//TODO here
|
//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)
|
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> {
|
fn unify(&mut self, t1: Type, t2: Type) -> InferResult<Type> {
|
||||||
unimplemented!()
|
println!("Unify ain't done yo");
|
||||||
|
Ok(t1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user