Documentation

Lean.Meta.InferType

def Lean.Expr.instantiateBetaRevRange (e : Expr) (start stop : Nat) (args : Array Expr) :

Auxiliary function for instantiating the loose bound variables in e with args[start...stop]. This function is similar to instantiateRevRange, but it applies beta-reduction when we instantiate a bound variable with a lambda expression.

Example: Given the term #0 a, and start := 0, stop := 1, args := #[fun x => x] the result is a instead of (fun x => x) a. This reduction is useful when we are inferring the type of eliminator-like applications. For example, given (n m : Nat) (f : Nat → Nat) (h : m = n), the type of Eq.subst (motive := fun x => f m = f x) h rfl is motive n which is (fun (x : Nat) => f m = f x) n. This function reduces the new application to f m = f n.

We use this to implement inferAppType.

Instances For
    Instances For
      def Lean.Meta.throwIncorrectNumberOfLevels {α : Type} (constName : Name) (us : List Level) :
      Instances For
        def Lean.Meta.throwTypeExpected {α : Type} (type : Expr) :
        Instances For

          If type : sort and sort reduces to Sort u for some u, then getLevel type returns u.

          If sort is an assignable MVar, then getLevel type produces a fresh level metavariable ?u, assigns the MVar to Sort ?u and returns ?u.

          Instances For
            def Lean.Meta.throwUnknownMVar {α : Type} (mvarId : MVarId) :
            Instances For
              @[inline]

              Ensure MetaM configuration is strong enough for inferring/checking types. For example, beta := true is essential when type checking.

              Remark: we previously used the default configuration here, but this is problematic because it overrides unrelated configurations.

              Instances For
                @[export lean_infer_type]
                Instances For

                  isPropQuick e is an "approximate" predicate which returns LBool.true if e is a proposition.

                  isProp e returns true if e is a proposition.

                  If e contains metavariables, it may not be possible to decide whether it is a proposition or not. We return false in this case. We considered using LBool and returning LBool.undef, but we have no applications for it.

                  Instances For

                    isProofQuick e is an "approximate" predicate which returns LBool.true if e is a proof.

                    Check if e is a proof, i.e. the type of e is a proposition.

                    Instances For

                      isTypeQuick e is an "approximate" predicate which returns LBool.true if e is a type.

                      Returns true iff the type of e is a Sort _.

                      Instances For

                        Returns u iff type is Sort u or As → Sort u.

                        Instances For

                          Returns true iff type is Sort _ or As → Sort _.

                          Instances For

                            Returns true iff type is Prop or As → Prop.

                            Instances For

                              Returns true iff e : Sort _ or e : (forall As, Sort _). Remark: it subsumes isType

                              Instances For

                                Given n and a non-dependent function type α₁ → α₂ → ... → αₙ → Sort u, returns the types α₁, α₂, ..., αₙ. Throws an error if there are not at least n argument types or if a later argument type depends on a prior one (i.e., it's a dependent function type).

                                This can be used to infer the expected type of the alternatives when constructing a MatcherApp.

                                Instances For

                                  Infers the types of the next n parameters that e expects. See arrowDomainsN.

                                  Instances For