diff options
Diffstat (limited to 'src/type/conversion.rs')
-rw-r--r-- | src/type/conversion.rs | 15 |
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]) |