Have + do something different with strings

Needed to introduce polymorphism soon
This commit is contained in:
greg 2017-10-10 02:45:25 -07:00
parent 2f18529bcc
commit 6c60794485
2 changed files with 15 additions and 1 deletions

View File

@ -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),

View File

@ -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)),