aboutsummaryrefslogtreecommitdiff
path: root/src/type/conversion.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-22 23:48:35 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-22 23:48:35 +0300
commit12a7cbf8ef911f0cbfcbd13d1c888025fa411de4 (patch)
tree9f76d6676cb6d27ab6966e4a7bbe325d744de31c /src/type/conversion.rs
parent16e1791ea6c404b16c9c9353333e887a75d9d427 (diff)
downloadmyslip-12a7cbf8ef911f0cbfcbd13d1c888025fa411de4.tar.gz
myslip-12a7cbf8ef911f0cbfcbd13d1c888025fa411de4.zip
fix: added missing conversions and generic inferring for coproducts
Diffstat (limited to 'src/type/conversion.rs')
-rw-r--r--src/type/conversion.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/type/conversion.rs b/src/type/conversion.rs
index ab858e6..54fc59d 100644
--- a/src/type/conversion.rs
+++ b/src/type/conversion.rs
@@ -11,7 +11,7 @@ impl Type {
/// 0. self == other => self
/// 1. (T T ... T T) -> (T ...)
/// 2. self = concrete and other = variable type => self,
- /// 3. arrow types and lists are mapped
+ /// 3. arrow types and lists and sums are mapped
/// 4. makes [self] self if self == other
pub fn convert(self, other: &Type) -> Result<Type, ()> {
let (ty, ctx) = self.convert_ctx(other)?;
@@ -62,6 +62,14 @@ impl Type {
Ok((arr(t1, t2), ctx))
},
+ (SumType(a1, a2), SumType(b1, b2)) => {
+ let (t1, newctx) = a1.convert_ctx(b1)?;
+ ctx.extend(newctx);
+ let (t2, newctx) = a2.convert_ctx(b2)?;
+ ctx.extend(newctx);
+ Ok((sumtype(t1, t2), ctx))
+ },
+
(List(v), VecOf(ty)) => match v.get(0) {
Some(t) => {
let (convt, newctx) = t.clone().convert_ctx(ty)?;
@@ -163,6 +171,11 @@ mod tests {
.convert(&arr(vt("T"), vt("T"))),
Ok(arr(arr(vecof(Integer), Integer), arr(vecof(Integer), Integer)))
);
+ assert_eq!(
+ sumtype(sumtype(vecof(Integer), Integer), sumtype(vecof(Integer), Integer))
+ .convert(&sumtype(vt("T"), vt("T"))),
+ Ok(sumtype(sumtype(vecof(Integer), Integer), sumtype(vecof(Integer), Integer)))
+ );
assert!(
List(vec![Integer, Boolean])