Zulip Chat Archive

Stream: lean4

Topic: inferType and expressions introduced by have


Tomaz Gomes Mascarenhas (Oct 17 2022 at 19:54):

Hello! I would like to understand why inferType gives me this output when used in an expression introduced by a have without specifying it's type. I am writting a tactic that produces several intermediate terms using have and I would like to not have to specify their type, but this behavior of inferType is causing some trouble. Is there a way around it?

import Lean
open Lean Lean.Elab.Tactic

syntax (name := tac) "tac" term : tactic

@[tactic tac] def evalTac : Tactic := fun stx => withMainContext do
  let e  elabTerm stx[1] none
  let t  Meta.inferType e
  logInfo t

example : A  B  True := by
  intro h
  tac h -- A ∨ B
  have h2 := h
  tac h2 -- ?m655
  exact True.intro

Adam Topaz (Oct 17 2022 at 20:04):

I'm not an expert, but docs4#Lean.instantiateMVars might be required.

Adam Topaz (Oct 17 2022 at 20:04):

At least the following seems to work for me:

@[tactic tac] def evalTac : Tactic := fun stx => withMainContext do
  let e  elabTerm stx[1] none
  let t  instantiateMVars ( Meta.inferType e)
  logInfo t

Tomaz Gomes Mascarenhas (Oct 17 2022 at 22:02):

that works, thanks!


Last updated: Dec 20 2023 at 11:08 UTC