More typing work
This commit is contained in:
parent
020819550b
commit
9a09f40222
@ -13,8 +13,15 @@ type TypeResult<T> = Result<T, TypeError>;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct TypeError { }
|
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 {
|
impl TypeContext {
|
||||||
@ -31,9 +38,35 @@ impl TypeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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!()
|
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)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user