Solving Constraints [blog/lti/solve_code]
Solving Constraints [blog/lti/solve_code]
pub fn solve(self : Constraints, ty : Type) -> Map[Var, Type]? {
let f = (vs : (Var, Subtype)) => {
let { l, r } = vs.1
let v = match ty.variance(vs.0) {
Constant | Covariant => Some(l)
Contravariant => Some(r)
Invariant => if l == r { Some(l) } else { None }
}
v.map(v => (vs.0, v))
}
let i = self.inner().iter().filter_map(f)
guard i.count() == self.inner().size() else { None }
Some(Map::from_iter(i))
}