Implemented coercions when subtracting able functios

pull/1/head
ondra05 2021-12-09 17:18:37 +01:00
parent 647fffbfd2
commit 3f1b6d2387
1 changed files with 29 additions and 1 deletions

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() {