diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index e900ea7..5f287f3 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -16,10 +16,24 @@ struct TypeError { } #[derive(Debug, Clone)] enum MonoType { Var(Rc), - Const(Rc), + Const(TConst), Arrow(Rc) } +#[derive(Debug, Clone)] +enum TConst { + User(Rc), + Unit, + Nat, + Int +} + +impl TConst { + fn user(name: &str) -> TConst { + TConst::User(Rc::new(name.to_string())) + } +} + #[derive(Debug, Clone)] struct PolyType { vars: Vec>, @@ -41,7 +55,7 @@ impl TypeContext { impl TypeContext { fn infer_ast(&mut self, ast: &AST) -> TypeResult { - let mut output = MonoType::Const(Rc::new("Unit".to_string())); + let mut output = MonoType::Const(TConst::Unit); for statement in ast.0.iter() { output = match statement { Statement::ExpressionStatement(ref expr) => self.infer_expr(expr)?, @@ -59,14 +73,14 @@ impl TypeContext { } fn infer_decl(&mut self, expr: &Declaration) -> TypeResult { - Ok(MonoType::Const(Rc::new("Unimplemented".to_string()))) + Ok(MonoType::Const(TConst::user("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()))), - _ => Ok(MonoType::Const(Rc::new("Unimplemented".to_string()))) + NatLiteral(_) => Ok(MonoType::Const(TConst::Nat)), + _ => Ok(MonoType::Const(TConst::user("unimplemented"))) } } }