From 9a09f402228eb614984a118c452501c050936a8e Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 7 Nov 2018 03:39:31 -0800 Subject: [PATCH] More typing work --- schala-lang/language/src/typechecking.rs | 37 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index a87bb13..68c610d 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -13,8 +13,15 @@ type TypeResult = Result; #[derive(Debug, Clone)] struct TypeError { } -struct Type { +enum MonoType { + Var(Rc), + Const(Rc), + Arrow(Rc) +} +struct PolyType { + vars: Vec>, + 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 { + 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 { + 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 { unimplemented!() } + + fn infer_expr_type(&mut self, expr_type: &ExpressionType) -> TypeResult { + use self::ExpressionType::*; + match expr_type { + NatLiteral(_) => Ok(MonoType::Const(Rc::new("Nat".to_string()))), + _ => unimplemented!() + } + } } #[cfg(test)]