More typing work

This commit is contained in:
greg 2018-11-07 03:39:31 -08:00
parent 020819550b
commit 9a09f40222
1 changed files with 35 additions and 2 deletions

View File

@ -13,8 +13,15 @@ type TypeResult<T> = Result<T, TypeError>;
#[derive(Debug, Clone)]
struct TypeError { }
struct Type {
enum MonoType {
Var(Rc<String>),
Const(Rc<String>),
Arrow(Rc<String>)
}
struct PolyType {
vars: Vec<Rc<String>>,
ty: MonoType
}
impl TypeContext {
@ -31,9 +38,35 @@ impl TypeContext {
}
impl TypeContext {
fn infer_ast(&mut self, ast: &AST) -> TypeResult<()> {
fn infer_ast(&mut self, ast: &AST) -> TypeResult<MonoType> {
let mut output = MonoType::Const(Rc::new("Unit".to_string()));
for statement in ast.0.iter() {
match statement {
Statement::ExpressionStatement(ref expr) => self.infer_expr(expr)?,
Statement::Declaration(ref decl) => self.infer_decl(decl)?,
};
}
Ok(output)
}
fn infer_expr(&mut self, expr: &Expression) -> TypeResult<MonoType> {
match expr {
Expression(expr_type, Some(type_anno)) => unimplemented!(),
Expression(expr_type, None) => self.infer_expr_type(expr_type)
}
}
fn infer_decl(&mut self, expr: &Declaration) -> TypeResult<MonoType> {
unimplemented!()
}
fn infer_expr_type(&mut self, expr_type: &ExpressionType) -> TypeResult<MonoType> {
use self::ExpressionType::*;
match expr_type {
NatLiteral(_) => Ok(MonoType::Const(Rc::new("Nat".to_string()))),
_ => unimplemented!()
}
}
}
#[cfg(test)]