Zulip Chat Archive

Stream: lean4

Topic: 'failed to infer binder type' error


Juneyoung Lee (Feb 12 2024 at 21:12):

Hi all, I defined a toy tactic and used it as follows:

macro "add_true" h:ident: tactic =>
  `(tactic|
      have ($h:ident): True := True.intro
    )

example: True := by
  add_true h_new
  sorry

However, it shows an error message at h_new as follows:

failed to infer binder type

h_new: ?m.4780

Any idea how this can be resolved?

Damiano Testa (Feb 12 2024 at 21:23):

This works:

import Std
open Lean Elab Tactic

elab "add_true" h:ident : tactic => do
  evalTactic ( `(tactic| have $h:ident: True := True.intro ))

example: True := by
  add_true h_new
  sorry

Jannis Limperg (Feb 12 2024 at 21:27):

I think the parentheses around $h:ident make it into a pattern and then Lean gets confused. Without the parentheses, it works:

macro "add_true" h:ident: tactic =>
  `(tactic|
      have $h:ident : True := True.intro
    )

example: True := by
  add_true h_new

Last updated: May 02 2025 at 03:31 UTC