aboutsummaryrefslogtreecommitdiff
path: root/src/type/conversion.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-14 14:02:27 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-14 14:02:27 +0300
commit907bd54d19f6bf14a130a136df6f37cc5d256468 (patch)
tree28e282e040d05f107833a48fa27e8498746dfbda /src/type/conversion.rs
parent52263c39dd6006cce5fc938ec60751ab45b73f8b (diff)
downloadmyslip-907bd54d19f6bf14a130a136df6f37cc5d256468.tar.gz
myslip-907bd54d19f6bf14a130a136df6f37cc5d256468.zip
feat: parsing of new types (T, (int ...), (int bool)) etc. also fixed bug in into_type (it didn't handle lists recursively)
Diffstat (limited to 'src/type/conversion.rs')
-rw-r--r--src/type/conversion.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/type/conversion.rs b/src/type/conversion.rs
index 5d29ba0..baeab90 100644
--- a/src/type/conversion.rs
+++ b/src/type/conversion.rs
@@ -94,6 +94,7 @@ impl Type {
/// List(vec![Integer, Boolean]).into_type(&vecof(vt("T"))),
/// Ok(vecof(vt("T")))
/// );
+ /// assert_eq!(List(vec![Boolean, Integer, Integer]).into_type(&List(vec![Boolean, vt("T"), vt("T")])), Ok(List(vec![Boolean, Integer, Integer])))
/// ```
///
/// Though the conversion from (a) to a is also convenient:
@@ -115,6 +116,14 @@ impl Type {
(List(x), b) if x.len() == 1 && &x[0] == b => Ok(x[0].clone()),
+ (List(v1), List(v2)) if v1.len() == v2.len() => {
+ let mut res = vec![];
+ for (t1, t2) in v1.into_iter().zip(v2) {
+ res.push(t1.clone().into_type(&t2)?);
+ }
+ Ok(List(res))
+ }
+
(List(v), VecOf(b)) => match v.get(0) {
Some(first) => {
let cand = v.into_iter()