Skip to content
Snippets Groups Projects
Commit af44cba3 authored by belazy's avatar belazy
Browse files

Resolve "Fix remaining TODO #34" ✨️

Closes #64 🐔️👍️

🦀️🍰🦀️🍰🦀️🍰

* fix : remaining todo
parent 8564629b
No related branches found
No related tags found
1 merge request!53Resolve "Fix remaining TODO #34"
Pipeline #11864 canceled with stages
in 4 minutes and 18 seconds
......@@ -110,57 +110,54 @@ impl<'arena> Arena<'arena> {
/// Infers the type of the term `t`, living in arena `self`.
pub fn infer(&mut self, t: Term<'arena>) -> ResultTerm<'arena> {
t.get_type_or_try_init(|| {
match *t {
Prop => Ok(self.type_usize(0)),
Type(ref i) => Ok(self.type_(i.clone() + BigUint::from(1_u64).into())),
Var(_, type_) => Ok(type_),
Prod(t, u) => {
let univ_t = self.infer(t)?;
let univ_u = self.infer(u)?;
// TODO: relax normalization to whnf once it is itself relaxed (#34)
let univ_t = self.normal_form(univ_t);
let univ_u = self.normal_form(univ_u);
self.imax(univ_t, univ_u)
},
Abs(t, u) => {
let type_t = self.infer(t)?;
match *type_t {
Type(_) | Prop => {
let type_u = self.infer(u)?;
Ok(self.prod(t, type_u))
},
_ => Err(Error {
kind: TypeCheckerError::NotUniverse(type_t).into(),
}),
}
},
App(t, u) => {
let type_t = self.infer(t)?;
let type_t = self.whnf(type_t);
match *type_t {
Prod(arg_type, cls) => {
let type_u = self.infer(u)?;
if self.conversion(type_u, arg_type) {
Ok(self.substitute(cls, u, 1))
} else {
Err(Error {
kind: TypeCheckerError::WrongArgumentType(t, arg_type, TypedTerm(u, type_u)).into(),
})
}
},
_ => Err(Error {
kind: TypeCheckerError::NotAFunction(TypedTerm(t, type_t), u).into(),
}),
}
},
}
t.get_type_or_try_init(|| match *t {
Prop => Ok(self.type_usize(0)),
Type(ref i) => Ok(self.type_(i.clone() + BigUint::from(1_u64).into())),
Var(_, type_) => Ok(type_),
Prod(t, u) => {
let univ_t = self.infer(t)?;
let univ_u = self.infer(u)?;
let univ_t = self.whnf(univ_t);
let univ_u = self.whnf(univ_u);
self.imax(univ_t, univ_u)
},
Abs(t, u) => {
let type_t = self.infer(t)?;
match *type_t {
Type(_) | Prop => {
let type_u = self.infer(u)?;
Ok(self.prod(t, type_u))
},
_ => Err(Error {
kind: TypeCheckerError::NotUniverse(type_t).into(),
}),
}
},
App(t, u) => {
let type_t = self.infer(t)?;
let type_t = self.whnf(type_t);
match *type_t {
Prod(arg_type, cls) => {
let type_u = self.infer(u)?;
if self.conversion(type_u, arg_type) {
Ok(self.substitute(cls, u, 1))
} else {
Err(Error {
kind: TypeCheckerError::WrongArgumentType(t, arg_type, TypedTerm(u, type_u)).into(),
})
}
},
_ => Err(Error {
kind: TypeCheckerError::NotAFunction(TypedTerm(t, type_t), u).into(),
}),
}
},
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment