Zulip Chat Archive

Stream: new members

Topic: questions about type class instance


Winston Yin (Jun 22 2021 at 08:20):

I'm trying to do two things.

  1. Define a structure containing, say, (ι : Type*), but also requiring nontrivial ι, perhaps by type class inference rather than explicit proof. E.g.
structure my_struct :=
(ι : Type*)
[nontriv_ι : nontrivial ι]
...
  1. In a proof, I need to provide a term for the type Π₀ i : ι, M i. When I construct this term using an object of my_struct, Lean fails to see nontriv_ι when synthesising the nontrivial ι for the dfinsupp. How can I help Lean see the type class instance provided by nontriv_ι? Lean keeps saying "failed to synthesise type class instance".

Kevin Buzzard (Jun 22 2021 at 08:21):

The square brackets in the definition do not make it an instance. Try attribute [instance] my_struct.nontriv_ι after the definition and see if this fixes things.

Eric Wieser (Jun 22 2021 at 08:37):

I think for this specific example #lint will complain the instance is dangerous / impossible, but that might just be because you over-minimized the example


Last updated: Dec 20 2023 at 11:08 UTC