Documentation

Lean.Elab.Match

We treat @x as atomic to avoid unnecessary extra local declarations from being inserted into the local context. Recall that expandMatchAltsIntoMatch uses @ modifier. Thus this is kind of discriminant is quite common.

Remark: if the discriminat is Systax.missing, we abort the elaboration of the match-expression. This can happen due to error recovery. Example

example : (p ∨ p) → p := fun h => match

If we don't abort, the elaborator loops because we will keep trying to expand

match

into

let d := ; match

Recall that Syntax.setArg stx i arg is a no-op when i is out-of-bounds.

Equations
  • One or more equations did not get rendered due to their size.
structure Lean.Elab.Term.Discr:
Type
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
  • When visiting an assigned metavariable, if it has an user-name. We save it here. We want to preserve these user-names when generating new pattern variables.

    userName : Lean.Name
  • Pattern variables that were explicitly provided by the user. Recall that implicit parameters and _ are elaborated as metavariables, and then converted into pattern variables by the normalize procedure.

    explicitPatternVars : Array Lean.FVarId

Return true iff e is an explicit pattern variable provided by the user.

Equations
  • One or more equations did not get rendered due to their size.

Normalize the pattern and collect all patterns variables (explicit and implicit). This method is the one that decides where the inaccessible annotations must be inserted. The pattern variables are both free variables (for explicit pattern variables) and metavariables (for implicit ones). Recall that mkLambdaFVars now allows us to abstract both free variables and metavariables.

Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.

Main method for withDepElimPatterns.

  • PatternVarDecls: are the explicit pattern variables provided by the user.
  • ps: are the patterns provided by the user.
  • matchType: the expected typ for this branch. It depends on the explicit pattern variables and the implicit ones that are still represented as metavariables, and are found by this function.
  • k is the continuation that is executed in an updated local context with the all pattern variables (explicit and implicit). Note that, patternVarDecls are all replaced since they may depend on implicit pattern variables (i.e., metavariables) that are converted into new free variables by this method.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.

Pattern matching. match e, ... with | p, ... => f | ... matches each given term e against each pattern p of a match alternative. When all patterns of an alternative match, the match term evaluates to the value of the corresponding right-hand side f with the pattern variables bound to the respective matched values.

Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.

Empty match/ex falso. nomatch e is of arbitrary type α : Sort u if Lean can show that an empty set of patterns is exhaustive given e's type, e.g. because it has no constructors.

Equations
  • One or more equations did not get rendered due to their size.