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 200d0f9867
commit ddd861fbea
2 changed files with 15 additions and 1 deletions

View File

@ -85,6 +85,7 @@ impl ReplState {
let opstr: &str = &op.0; let opstr: &str = &op.0;
Ok(match (opstr, evaled_lhs, evaled_rhs) { Ok(match (opstr, evaled_lhs, evaled_rhs) {
("+", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l + r), ("+", 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), ("*", 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::Type::*;
use self::TypeConst::*; 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( Ok(
TConst(FunctionT( TConst(FunctionT(
Box::new(TConst(Integer)), Box::new(TConst(Integer)),