This PR improves the `#print` command for structures to show all fields
and which parents the fields were inherited from, hiding internal
details such as which parents are represented as subobjects. This
information is still present in the constructor if needed. The pretty
printer for private constants is also improved, and it now handles
private names from the current module like any other name; private names
from other modules are made hygienic.
Example output for `#print Monad`:
```
class Monad.{u, v} (m : Type u → Type v) : Type (max (u + 1) v)
number of parameters: 1
parents:
Monad.toApplicative : Applicative m
Monad.toBind : Bind m
fields:
Functor.map : {α β : Type u} → (α → β) → m α → m β
Functor.mapConst : {α β : Type u} → α → m β → m α
Pure.pure : {α : Type u} → α → m α
Seq.seq : {α β : Type u} → m (α → β) → (Unit → m α) → m β
SeqLeft.seqLeft : {α β : Type u} → m α → (Unit → m β) → m α
SeqRight.seqRight : {α β : Type u} → m α → (Unit → m β) → m β
Bind.bind : {α β : Type u} → m α → (α → m β) → m β
constructor:
Monad.mk.{u, v} {m : Type u → Type v} [toApplicative : Applicative m] [toBind : Bind m] : Monad m
resolution order:
Monad, Applicative, Bind, Functor, Pure, Seq, SeqLeft, SeqRight
```
Suggested by Floris van Doorn [on
Zulip](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/.23print.20command.20for.20structures/near/482503637).
100 lines
2.7 KiB
Text
100 lines
2.7 KiB
Text
#print Nat
|
||
|
||
private def foo (x : Nat) : Nat := x + 1
|
||
|
||
/-- info: hello -/
|
||
#guard_msgs in #print "hello"
|
||
/--
|
||
info: def id.{u} : {α : Sort u} → α → α :=
|
||
fun {α} a => a
|
||
-/
|
||
#guard_msgs in #print id
|
||
/-- info: axiom propext : ∀ {a b : Prop}, (a ↔ b) → a = b -/
|
||
#guard_msgs in #print propext
|
||
/--
|
||
info: def Inhabited.default.{u} : {α : Sort u} → [self : Inhabited α] → α :=
|
||
fun α [self : Inhabited α] => self.1
|
||
-/
|
||
#guard_msgs in #print default
|
||
/--
|
||
info: protected def ReaderT.read.{u, v} : {ρ : Type u} → {m : Type u → Type v} → [inst : Monad m] → ReaderT ρ m ρ :=
|
||
fun {ρ} {m} [Monad m] => pure
|
||
-/
|
||
#guard_msgs in #print ReaderT.read
|
||
/--
|
||
info: structure Prod.{u, v} (α : Type u) (β : Type v) : Type (max u v)
|
||
number of parameters: 2
|
||
fields:
|
||
Prod.fst : α
|
||
Prod.snd : β
|
||
constructor:
|
||
Prod.mk.{u, v} {α : Type u} {β : Type v} (fst : α) (snd : β) : α × β
|
||
-/
|
||
#guard_msgs in #print Prod
|
||
/-- info: constructor Prod.mk.{u, v} : {α : Type u} → {β : Type v} → α → β → α × β -/
|
||
#guard_msgs in #print Prod.mk
|
||
/--
|
||
info: inductive Nat : Type
|
||
number of parameters: 0
|
||
constructors:
|
||
Nat.zero : Nat
|
||
Nat.succ : Nat → Nat
|
||
-/
|
||
#guard_msgs in #print Nat
|
||
/-- info: constructor Nat.succ : Nat → Nat -/
|
||
#guard_msgs in #print Nat.succ
|
||
/--
|
||
info: recursor Nat.rec.{u} : {motive : Nat → Sort u} →
|
||
motive Nat.zero → ((n : Nat) → motive n → motive n.succ) → (t : Nat) → motive t
|
||
-/
|
||
#guard_msgs in #print Nat.rec
|
||
/--
|
||
info: @[reducible] def Nat.casesOn.{u} : {motive : Nat → Sort u} →
|
||
(t : Nat) → motive Nat.zero → ((n : Nat) → motive n.succ) → motive t :=
|
||
fun {motive} t zero succ => Nat.rec zero (fun n n_ih => succ n) t
|
||
-/
|
||
#guard_msgs in #print Nat.casesOn
|
||
/--
|
||
info: private def foo : Nat → Nat :=
|
||
fun x => x + 1
|
||
-/
|
||
#guard_msgs in #print foo
|
||
/-- info: Quotient primitive Quot.mk.{u} : {α : Sort u} → (r : α → α → Prop) → α → Quot r -/
|
||
#guard_msgs in #print Quot.mk
|
||
/--
|
||
info: Quotient primitive Quot.ind.{u} : ∀ {α : Sort u} {r : α → α → Prop} {β : Quot r → Prop},
|
||
(∀ (a : α), β (Quot.mk r a)) → ∀ (q : Quot r), β q
|
||
-/
|
||
#guard_msgs in #print Quot.ind
|
||
/-- info: Quotient primitive Quot.mk.{u} : {α : Sort u} → (r : α → α → Prop) → α → Quot r -/
|
||
#guard_msgs in #print Quot.mk
|
||
|
||
/-!
|
||
Structure with diamond inheritance
|
||
-/
|
||
structure A where
|
||
a : Nat
|
||
structure B extends A where
|
||
b : Nat
|
||
structure C extends A where
|
||
c : Nat
|
||
structure D extends B, C where
|
||
d : Nat
|
||
|
||
/--
|
||
info: structure D : Type
|
||
number of parameters: 0
|
||
parents:
|
||
D.toB : B
|
||
D.toC : C
|
||
fields:
|
||
A.a : Nat
|
||
B.b : Nat
|
||
C.c : Nat
|
||
D.d : Nat
|
||
constructor:
|
||
D.mk (toB : B) (c d : Nat) : D
|
||
resolution order:
|
||
D, B, C, A
|
||
-/
|
||
#guard_msgs in #print D
|