Implemented coercions when subtracting able functios

This commit is contained in:
Erin 2021-12-09 17:18:37 +01:00 committed by ondra05
parent c92cb7e818
commit 6430387119

View file

@ -472,7 +472,35 @@ impl ops::Sub for Value {
tape_len: lhs_tl,
},
},
Functio::Able { params, body } => todo!(),
Functio::Able {
params: lhs_params,
body: lhs_body,
} => match rhs.into_functio() {
Functio::Able {
params: rhs_params,
body: rhs_body,
} => Functio::Able {
params: lhs_params
.into_iter()
.zip(rhs_params.into_iter())
.filter_map(|(l, r)| if l != r { Some(l) } else { None })
.collect(),
body: lhs_body
.into_iter()
.zip(rhs_body.into_iter())
.filter_map(|(l, r)| if l != r { Some(l) } else { None })
.collect(),
},
rhs => Value::Int(
Value::Functio(Functio::Able {
params: lhs_params,
body: lhs_body,
})
.into_i32()
- Value::Functio(rhs).into_i32(),
)
.into_functio(),
},
Functio::Chain { functios, kind } => todo!(),
Functio::Eval(lhs_code) => Functio::Eval(lhs_code.replace(
&match rhs.into_functio() {