From f2c6556c2ae063cf1acb56666004c69953fd287b Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 9 Oct 2017 00:22:42 -0700 Subject: [PATCH] Use name TypeVariable --- src/schala_lang/type_check.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 465aedb..0ff400c 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -46,8 +46,8 @@ impl SymbolTable { } } } - fn lookup(&mut self, binding: &Rc) -> Option { - use self::SchalaType::*; + fn lookup(&mut self, binding: &Rc) -> Option { + use self::TypeVariable::*; Some(Function(Box::new(Integer), Box::new(Boolean))) } } @@ -69,17 +69,17 @@ impl TypeContext { } #[derive(Debug, PartialEq, Clone)] -pub enum SchalaType { +pub enum TypeVariable { Integer, Boolean, Unit, - Function(Box, Box), + Function(Box, Box), Bottom, } -impl SchalaType { - fn from_anno(anno: &TypeName) -> SchalaType { - use self::SchalaType::*; +impl TypeVariable { + fn from_anno(anno: &TypeName) -> TypeVariable { + use self::TypeVariable::*; match anno { &TypeName::Singleton { ref name, .. } => { @@ -94,7 +94,7 @@ impl SchalaType { } } -type TypeCheckResult = Result; +type TypeCheckResult = Result; // from Niko's talk /* fn type_check(expression, expected_ty) -> Ty { @@ -115,7 +115,7 @@ type TypeCheckResult = Result; impl TypeContext { pub fn type_check(&mut self, ast: &AST) -> TypeCheckResult { - let mut last = SchalaType::Unit; + let mut last = TypeVariable::Unit; for statement in ast.0.iter() { match statement { &Statement::Declaration(ref _decl) => { @@ -135,10 +135,10 @@ impl TypeContext { Ok(match (&expr.0, &expr.1) { (ref _t, &Some(ref anno)) => { //TODO make this better, - SchalaType::from_anno(anno) + TypeVariable::from_anno(anno) }, - (&IntLiteral(_), _) => SchalaType::Integer, - (&BoolLiteral(_), _) => SchalaType::Boolean, + (&IntLiteral(_), _) => TypeVariable::Integer, + (&BoolLiteral(_), _) => TypeVariable::Boolean, (&Variable(ref name), _) => self.symbol_table .lookup(name) .ok_or(format!("Couldn't find {}", name))?, @@ -147,18 +147,18 @@ impl TypeContext { let f_type = self.infer(&*f)?; let arg_type = self.infer(arguments.get(0).unwrap())?; // TODO fix later match f_type { - SchalaType::Function(box t1, box ret_type) => { + TypeVariable::Function(box t1, box ret_type) => { let _ = self.unify(&t1, &arg_type)?; ret_type }, _ => return Err(format!("Type error")) } }, - _ => SchalaType::Unit, + _ => TypeVariable::Unit, }) } - fn unify(&mut self, t1: &SchalaType, t2: &SchalaType) -> TypeCheckResult { + fn unify(&mut self, t1: &TypeVariable, t2: &TypeVariable) -> TypeCheckResult { if t1 == t2 { Ok(t1.clone()) } else {