-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: universe inference for Prop
-valued structures/inductives
#2695
Conversation
Thanks for your contribution! Please make sure to follow our Commit Convention. |
95e4f23
to
c00a093
Compare
leanprover-community-mathlib4-bot
commented
Oct 16, 2023
•
edited by leanprover-community-bot
Loading
edited by leanprover-community-bot
|
src/Init/Core.lean
Outdated
@@ -1684,15 +1684,15 @@ axiom ofReduceNat (a b : Nat) (h : reduceNat a = b) : a = b | |||
`IsAssociative op` says that `op` is an associative operation, | |||
i.e. `(a ∘ b) ∘ c = a ∘ (b ∘ c)`. It is used by the `ac_rfl` tactic. | |||
-/ | |||
class IsAssociative {α : Sort u} (op : α → α → α) where | |||
class IsAssociative {α : Sort u} (op : α → α → α) : Type where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO these should be Props, this is exactly the kind of issue we are hoping to avoid by changing the default
src/Init/Prelude.lean
Outdated
@@ -807,7 +807,7 @@ decidability instance instead of the proposition, which has no code). | |||
If a proposition `p` is `Decidable`, then `(by decide : p)` will prove it by | |||
evaluating the decidability instance to `isTrue h` and returning `h`. | |||
-/ | |||
class inductive Decidable (p : Prop) where | |||
class inductive Decidable (p : Prop) : Type where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug, it should not infer Prop
here because the inductive has two constructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the current draft makes a hacky tweak to accLevel
, which I believe isn't the right solution, as explained in the issue (This is not meant for review just yet). When tweaking mkResultUniverse
, I end up getting some kernel errors regarding loose universe variables in sort-polymorphic inductives like PProd
, so there's still work to do.
310d0dd
to
41b7323
Compare
2fb4925
to
59ce249
Compare
Prop
-valued structures/inductivesProp
-valued structures/inductives
59ce249
to
bfb8937
Compare
bfb8937
to
1196faa
Compare
…c subsingletons 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` manually. 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. Thanks to @arthur-adjedj for the investigation in leanprover#2695. Closes leanprover#2690
…c subsingletons 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` manually. 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. Thanks to @arthur-adjedj for the investigation in leanprover#2695. Closes leanprover#2690
…c 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
Closes #2690
External Contribution Guidelines.