Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- instReprCurryType = { reprPrec := instReprCurryType.repr }
Equations
- instBEqCurryType = { beq := instBEqCurryType.beq }
Equations
- instBEqCurryType.beq (CurryType.phi a) (CurryType.phi b) = (a == b)
- instBEqCurryType.beq (a.arrow a_1) (b.arrow b_1) = (instBEqCurryType.beq a b && instBEqCurryType.beq a_1 b_1)
- instBEqCurryType.beq x✝¹ x✝ = false
Instances For
Equations
- One or more equations did not get rendered due to their size.
- instDecidableEqCurryType.decEq (CurryType.phi a) (CurryType.phi b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- instDecidableEqCurryType.decEq (CurryType.phi a) (a_1.arrow a_2) = isFalse ⋯
- instDecidableEqCurryType.decEq (a.arrow a_1) (CurryType.phi a_2) = isFalse ⋯
Instances For
Equations
- One or more equations did not get rendered due to their size.
- instReprTerm.repr (Term.var a) prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Term.var" ++ Std.Format.line ++ reprArg a)).group prec✝
Instances For
Equations
- instReprTypeCtx = { reprPrec := instReprTypeCtx.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- instReprPrincipalPair = { reprPrec := instReprPrincipalPair.repr }
Equations
- instToStringCurryType = { toString := curryTypeToString }
Equations
- instToStringTerm = { toString := termToString }
Equations
- One or more equations did not get rendered due to their size.
Substitute type variable x with type ty throughout the given type.
The caller must ensure the occurs-check holds (i.e., ¬occursIn x ty) to
prevent introducing a cyclic type.
Equations
- replaceVar x ty (CurryType.phi a) = if (a == x) = true then ty else CurryType.phi a
- replaceVar x ty (a.arrow a_1) = (replaceVar x ty a).arrow (replaceVar x ty a_1)
Instances For
A type substitution witnessing that left and right can be unified.
Carries apply : CurryType → CurryType together with three invariants used to
prove termination of unify:
vars_decreased: the free variables of any image are bounded by those ofleft,right, and the input type's own variables.vars_eq_then_id: if the variable-cardinality does not decrease,applyis the identity.subst_rec:applydistributes over arrow types.
Instances For
The variable count can never stay equal after a replaceVar substitution.
Formally, (vars (replaceVar a ty ty')).card ≠ (vars (.phi a) ∪ vars ty ∪ vars ty').card.
This is used to show that Subst.replace satisfies vars_eq_then_id by contradiction:
if cardinalities were equal, subset equality would follow (by ReplaceVarScope), but
a is in the RHS (vars (.phi a)) and absent from the LHS (ReplaceElim).
Substitution that replaces type variable a with ty everywhere, given the occurs-check
¬occursIn a ty.
Equations
- Subst.replace a ty ho = { apply := replaceVar a ty, vars_decreased := ⋯, vars_eq_then_id := ⋯, subst_rec := ⋯, uleft := CurryType.phi a, uright := ty }
Instances For
Like Subst.replace but with the Subst type indices swapped (Subst ty (.phi a) instead
of Subst (.phi a) ty). The underlying function is the same (replaceVar a ty);
invariants delegate to ReplaceVarScope and ReplaceAddsNewVars.
Equations
- Subst.replacer a ty ho = { apply := replaceVar a ty, vars_decreased := ⋯, vars_eq_then_id := ⋯, subst_rec := ⋯, uleft := CurryType.phi a, uright := ty }
Instances For
Composition of two substitutions. Given s1 : Subst a c and
s2 : Subst (s1.apply b) (s1.apply d), their composition s2 ∘ s1 is a
Subst (.arrow a b) (.arrow c d).
vars_decreased: chain the two subset inclusions viacalc.vars_eq_then_id: if the composition is variable-count-preserving, derive thats2 = id(by cardinality squeeze on s2's image), then thats1 = idsimilarly.subst_rec: each factor distributes over arrows; compose the two equations.
Equations
Instances For
Unification of two CurryTypes. Returns a Subst left right whose apply unifies the two
types, or none if no unifier exists (fails occurs check).
Termination measure: ((vars left ∪ vars right).card, size left + size right) lexicographically
- φp = φq: identity if equal, otherwise
replace p (φq). - φp, non-variable: occurs check; if clear,
replace p ty. - arrow cases: unify heads with
s1, then unifys1-images of tails withs2; compose. - non-variable, φp: symmetric to the φp case.
Equations
- unify (CurryType.phi p) (CurryType.phi q) = if ho : p = q then some (Subst.id (CurryType.phi p) (CurryType.phi q)) else some (Subst.replace p (CurryType.phi q) ⋯)
- unify (CurryType.phi p) right = if ho : occursIn p right = true then none else some (Subst.replace p right ⋯)
- unify (a.arrow b) (c.arrow d) = match unify a c with | none => none | some s1 => match unify (s1.apply b) (s1.apply d) with | none => none | some s2 => some (s1.comp s2)
- unify left (CurryType.phi p) = if ho : occursIn p left = true then none else some (Subst.replacer p left ⋯)
Instances For
Construct a CtxSubst ctx1 ctx2 from a list of (variable, type1, type2) triples,
a substitution function f, a proof that f distributes over arrows, and the two contexts.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract the underlying substitution function from an ExSubst.
Equations
- (ExSubst.from s).cast = s.apply
Instances For
Helper function to recursively unify a list of common variables. Crucially, it applies the substitution from unifying the first pair to the rest of the list before continuing the recursion.
Instances For
Unify two typing contexts by unifying the types assigned to their common variables.
Collects all variables present in both environments, runs unifyCtx' to recursively
unify and accumulate substitutions, and composes the resulting substitutions
left-to-right via foldl.
Returns none if any individual unification fails.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Look up the type assigned to variable c in the typing context.
Equations
- ctx.lookup c = List.lookup c ctx.env
Instances For
Principal-type algorithm helper. Infers a PrincipalPair for term t given initial context
ctx. Fresh type variables are allocated with next; type and context unification use
unify / unifyCtx. Returns none only if unification fails (term is untypeable).
.var c: return the existing type ifcis inctx, else allocate a fresh variable..abs x m: recursively infer form; ifxwas assigned a type, wrap asx.ty → m.ty; otherwise allocate a fresh type forx..app m n: infer formandnsequentially; unifyp1withp2 → a(fresha); then unify the two resulting contexts and apply the composed substitution.