Zulip Chat Archive

Stream: lean4

Topic: Could not unify polymorphic class


Leni Aniva (Apr 11 2024 at 00:44):

Consider this very contrived example:

example :  (a b: List Nat), List Nat := by
  intro a b

After the intro tactic, the current goal becomes

a b : List Nat
 List Nat

Then the tactic apply HAppend.hAppend fails due to this:

failed to synthesize
  HAppend ?α ?β (List Nat)

but curiously, this is fine:

  apply _ ++ _

is there a way to make apply HAppend.hAppend succeed here?

Leni Aniva (Apr 11 2024 at 00:54):

I think apply HAppend.hAppend should succeed and it should generate metavariables for the two type arguments ?α ?β

François G. Dorais (Apr 11 2024 at 06:31):

I understand this is probably a mwe, but it's usually a bad idea to use tactic mode to generate data terms. This case is very simple so tactic mode probably produces the same term in the end but this is just easier:

example :  (a b: List Nat), List Nat := HAppend.hAppend

In a proof of a theorem in tactic mode, when the arity of application is known in advance it is often a good idea to use refine instead of apply.

Damiano Testa (Apr 11 2024 at 07:20):

In your example, this also works: apply (HAppend.hAppend).

Damiano Testa (Apr 11 2024 at 07:25):

If you want the two type arguments to appear as goals (and the HAppend instance), then you can use apply @HAppend.hAppend _ _ _ ?_ ?_ ?_.

Damiano Testa (Apr 11 2024 at 08:43):

One more:

  apply HAppend.hAppend (self := ?_)

As far as I understand, this specifically asks apply to create a goal for self : HAppend α β γ and this is enough of a hint.

Kevin Buzzard (Apr 11 2024 at 08:48):

I am so totally confused by this thread :-) Maybe I shouldn't worry though, maybe this is all an artifact of using tactic mode to make data?

Eric Wieser (Apr 11 2024 at 09:02):

I think this is quite related to #mathlib4 > term vs by exact term, since

example (a b: List Nat) : List Nat := by
  exact HAppend.hAppend _ _

gives a different error to

example (a b: List Nat) : List Nat :=
  HAppend.hAppend _ _

Last updated: May 02 2025 at 03:31 UTC