Zulip Chat Archive

Stream: new members

Topic: Viewing instantiations


Paul Nelson (Jan 02 2024 at 19:37):

Is there a way to see which instances apply to a given type? I saw the following suggested in one the books, but they didn't work for me, so maybe they're out of date:

#print classes
#print instances inhabited
set_option trace.class_instances true

Alex J. Best (Jan 02 2024 at 19:45):

Which books are you looking at, there are quite a lot of differences between lean 3 and lean 4 so I'd recommend you stick to those aimed at lean 4 only

Alex J. Best (Jan 02 2024 at 19:46):

I think the easiest way to see this is on the docs, eg docs#Nat, if you click the dropdown "Instances for" you can see a list of all instances for nat defined in Mathlib (+Std + core). This is less helpful if you're working on your own project which adds a lot of stuff, but you can always run doc-gen4 on your project and get similar output

Kyle Miller (Jan 02 2024 at 19:50):

https://leanprover-community.github.io/mathlib4_docs/Std/Tactic/Instances.html#Std.Tactic.Instances.instancesCmd is useful

Kyle Miller (Jan 02 2024 at 19:50):

#instances Inhabited _ shows all Inhabited instances for example

Paul Nelson (Jan 02 2024 at 20:08):

Alex J. Best said:

Which books are you looking at, there are quite a lot of differences between lean 3 and lean 4 so I'd recommend you stick to those aimed at lean 4 only

https://lean-lang.org/theorem_proving_in_lean/type_classes.html, section 10.5

Paul Nelson (Jan 02 2024 at 20:10):

Guess I’ll switch to https://lean-lang.org/theorem_proving_in_lean4/ :)


Last updated: May 02 2025 at 03:31 UTC