From 6c60794485d465483cfe763570bb8e5a9335d48d Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 10 Oct 2017 02:45:25 -0700 Subject: [PATCH] Have + do something different with strings Needed to introduce polymorphism soon --- src/schala_lang/eval.rs | 1 + src/schala_lang/type_check.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/eval.rs b/src/schala_lang/eval.rs index 485da58..68987ec 100644 --- a/src/schala_lang/eval.rs +++ b/src/schala_lang/eval.rs @@ -85,6 +85,7 @@ impl ReplState { let opstr: &str = &op.0; Ok(match (opstr, evaled_lhs, evaled_rhs) { ("+", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l + r), + ("+", Str(s1), Str(s2)) => Str(format!("{}{}", s1, s2)), ("-", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l - r), ("*", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l * r), ("/", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l / r), diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 7aa42f6..14791f2 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -214,10 +214,23 @@ impl TypeContext { }) } - fn infer_op(&mut self, _op: &Operation) -> TypeCheckResult { + fn infer_op(&mut self, op: &Operation) -> TypeCheckResult { use self::Type::*; use self::TypeConst::*; + let opstr: &str = &op.0; + if opstr == "+" { + return Ok( + TConst(FunctionT( + Box::new(TConst(StringT)), + Box::new(TConst(FunctionT( + Box::new(TConst(StringT)), + Box::new(TConst(StringT)) + ))) + )) + ) + } + Ok( TConst(FunctionT( Box::new(TConst(Integer)),