lean4-htt/tests/lean/run/1074a.lean
Kyle Miller a35e6f4af7
feat: infer Prop for inductive/structure when defining syntactic subsingletons (#5517)
A `Prop`-valued inductive type is a syntactic subsingleton if it has at
most one constructor and all the arguments to the constructor are in
`Prop`. Such types have large elimination, so they could be defined in
`Type` or `Prop` without any trouble, though users tend to expect that
such types define a `Prop` and need to learn to insert `: Prop`.

Currently, the default universe for types is `Type`. This PR adds a
heuristic: if a type is a syntactic subsingleton with exactly one
constructor, and the constructor has at least one parameter, then the
`inductive` command will prefer creating a `Prop` instead of a `Type`.
For `structure`, we ask for at least one field.

More generally, for mutual inductives, each type needs to be a syntactic
subsingleton, at least one type must have one constructor, and at least
one constructor must have at least one parameter. The motivation for
this restriction is that every inductive type starts with a zero
constructors and each constructor starts with zero fields, and
stubbed-out types shouldn't be `Prop`.

Thanks to @arthur-adjedj for the investigation in #2695 and to @digama0
for formulating the heuristic.

Closes #2690
2024-10-08 22:39:38 +00:00

28 lines
564 B
Text

inductive Term : Type
| id2: Term -> Term -> Term
inductive Brx: Term -> Prop
| id2: Brx z -> Brx (Term.id2 n z)
def Brx.interp {a} (H: Brx a): Nat :=
match a with
| Term.id2 n z => by
let ⟨Hn, Hz⟩: True ∧ Brx z
:= by cases H <;> exact ⟨by simp, by assumption⟩;
exact Hz.interp
def Brx.interp_nil (H: Brx a): H.interp = H.interp
:=
by {
unfold interp
rfl
}
/--
info: Brx.interp.eq_1 (n z : Term) (H_2 : Brx (n.id2 z)) :
H_2.interp =
match ⋯ with
| ⋯ => Hz.interp
-/
#guard_msgs in
#check Brx.interp.eq_1