aboutsummaryrefslogtreecommitdiff
path: root/src/type/case.rs
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-21 12:35:37 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-21 12:35:37 +0300
commitd1c97e405230b6616ef834cf38be351e566a228e (patch)
tree7c75d9353b0b3cc9f08400c5d09e0b7552afc9c8 /src/type/case.rs
parenta70dcaa949f41c585f9aea5e79f2550053d8e857 (diff)
downloadmyslip-d1c97e405230b6616ef834cf38be351e566a228e.tar.gz
myslip-d1c97e405230b6616ef834cf38be351e566a228e.zip
feat: implemented coproducts according to tests
Diffstat (limited to 'src/type/case.rs')
-rw-r--r--src/type/case.rs97
1 files changed, 9 insertions, 88 deletions
diff --git a/src/type/case.rs b/src/type/case.rs
index d8871af..ae4eb77 100644
--- a/src/type/case.rs
+++ b/src/type/case.rs
@@ -120,99 +120,20 @@ impl SExp {
_ => Err(OtherError)
},
- _ => Err(OtherError), // maybe add nicer error?
-
- }
-
- // match (self, ty) {
-
- // (a, b) if a.infer_list_type(ctx.clone()) == Ok(b.clone()) =>
- // Ok(ctx.into_iter().collect()),
- // (a, b) if a.infer_type(ctx.clone()) == Ok(b.clone()) =>
- // Ok(ctx.into_iter().collect()),
-
- // (Atom(Var(name)), t) =>
- // Ok(ctx.into_iter()
- // .chain(iter::once((name, t)))
- // .collect()),
+ (se, SumType(l, r)) => match (&(se.parts())[..], (*l, *r)) {
+ ([op, exp], (l, _)) if *op == Atom(Inl) =>
+ exp.clone().matches_type_ctx(l, ctx.clone()),
+ ([op, exp], (_, r)) if *op == Atom(Inr) =>
+ exp.clone().matches_type_ctx(r, ctx.clone()),
+ _ => Err(OtherError),
+ },
- // (exp, VecOf(ty)) => {
- // let mut res: Vec<(String, Type)> =
- // ctx.clone().into_iter().collect();
- // let mut exps = exp.clone().parts();
- // // TODO: Nil or empty exp
- // let restpat = exps.remove(exps.len() - 1);
- // for exp in exps {
- // for et in exp.matches_type_ctx(*ty.clone(), ctx.clone())? {
- // res.push(et);
- // }
- // }
- // match restpat {
- // Atom(RestPat(name)) => {
- // res.push((name, vecof(ty)));
- // Ok(res)
- // },
- // t => {
- // for et in t.matches_type_ctx(*ty.clone(), ctx.clone())? {
- // res.push(et);
- // }
- // Ok(res)
- // }
- // }
- // },
- // (SCons(e1, e2), List(typelist)) => {
- // let explist = scons(e1.clone(), e2.clone()).parts();
- // let mut res: Vec<(String, Type)> =
- // ctx.clone().into_iter().collect();
- // if explist.len() == typelist.len() {
- // for (exp, ty) in explist.into_iter().zip(typelist) {
- // for (e, t) in exp.matches_type_ctx(ty, ctx.clone())? {
- // res.push((e, t));
- // }
- // }
- // Ok(res)
- // } else {
- // match explist.last().cloned() {
- // Some(Atom(RestPat(name))) => {
- // for (exp, ty) in explist.clone()
- // .into_iter()
- // .rev().skip(1).rev()
- // .zip(typelist.clone())
- // {
- // for (e, t) in exp.matches_type_ctx(ty, ctx.clone())? {
- // res.push((e, t));
- // }
- // }
- // res.push((
- // name,
- // List(typelist
- // .into_iter()
- // .skip(explist.len() - 1)
- // .collect())
- // ));
- // Ok(res)
- // },
- // _ => Err(InvalidPattern(TypeMismatch {
- // pattern: scons(e1.clone(), e2.clone()),
- // expected: List(typelist),
- // found: scons(e1, e2).infer_list_type(ctx)?,
- // })),
- // }
- // }
- // },
- // (e, t) => {
- // let found_ty = e.infer_list_type(ctx)?;
- // Err(InvalidPattern(TypeMismatch {
- // pattern: e,
- // expected: t,
- // found: found_ty
- // }))
- // },
+ _ => Err(OtherError), // maybe add nicer error?
- // }
+ }
}
}