English
Computationally, given a non-dependent function e between spaces, the elaboration tries to find compatible models for its domain and codomain.
Русский
Вычислительно, если функция e неопределенно зависимая между пространствами, проработчик пытается найти совместимые модели для области определения и кодом.
LaTeX
$$findModels(e, es) computes (srcI, tgtI) such that the type of e is compatible with src and target models.$$
Lean4
/-- If the type of `e` is a non-dependent function between spaces `src` and `tgt`, try to find a
model with corners on both `src` and `tgt`. If successful, return both models.
We pass `e` instead of just its type for better diagnostics.
If `es` is `some`, we verify that `src` and the type of `es` are definitionally equal. -/
def findModels (e : Expr) (es : Option Expr) : TermElabM (Expr × Expr) := do
let etype ← whnf <| ← instantiateMVars <| ← inferType e
match etype with
| .forallE _ src tgt _ =>
if tgt.hasLooseBVars then
-- TODO: try `T%` here, and if it works, add an interactive suggestion to use it
throwError "Term {e } is a dependent function, of type {etype}\nHint: you can use the `T%` \
elaborator to convert a dependent function to a non-dependent one"
let srcI ← findModel src
if let some es := es then
let estype ← inferType es
if !(← isDefEq estype <| ← mkAppM ``Set #[src]) then
throwError "The domain {src } of {e } is not definitionally equal to the carrier type of \
the set {es } : {estype}"
let tgtI ← findModel tgt (src, srcI)
return (srcI, tgtI)
| _ =>
throwError "Expected{(indentD e)}\nof type{indentD etype}\nto be a function"