-
Notifications
You must be signed in to change notification settings - Fork 79
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
feat(frontends/lean/pp): use forall notation for all pi types from a Type to a Prop #770
base: master
Are you sure you want to change the base?
Conversation
I had wondered about this behavior of the pretty printer before, and this Zulip thread led me to check how hard it would be to make the change. If it's unwanted, that's fine. One one hand, it's an improvement because you can tell immediately whether a pi type with a binding domain in Type is a Prop since it will always show forall notation. On the other you can't immediately tell whether a forall is dependent or not. I think it's still on the balance an improvement that helps align Lean with common practice mathematics at little cost. |
To an experienced user, I'd argue being able to spot a non-dependent binder at a glance is more valuable than matching pen and paper mathematics, but I understand the pedagogical appeal. Do you think using underscores for the variable names in non-dependent binders is a good idea? I think that would remove the downside regarding dependent types. |
I like this idea @eric-wieser. I added a mild hack to get this to work -- anonymous names can't round-trip anyway, so I made the binder pp routine print anonymous names as I generalized this to also apply to non-dependent pi types with non-explicit binders. For example, |
I created some conflicts in my other PR; some tests might need fixing yet. |
@eric-wieser I just noticed your other PRs and was in the process of getting my dev environment set up for lean to merge and test (I'm at Orsay for the year, by the way). Edit: Your merge looks good to me, thanks! The tests all pass locally too. |
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.
LGTM
This PR makes two modifications to the pretty printer for pi types: (1) if
α
is a Type andp
is a Prop thenα → p
pretty prints as∀ (_ : α), p
, and (2) non-dependent pi types with non-explicit binders such asΠ {x : α}, β
pretty print asΠ {_ : α}, β
, with a special case that instance implicits pretty print asΠ [foo α], β
rather thanΠ [_ : foo α], β
.Rationale: Recall that if
A : Sort u
andB : A → Sort v
we have thatΠ (a : A), B a : Sort (imax u v)
, and in particular whenv
is zero then∀ (a : A), B a : Prop
. Currently, whenq : Prop
then the non-dependent∀ (a : A), q
pretty prints asA → q : Prop
. This tends to be surprising whenA
is a Type, since the implicationA → q
is a proposition butA
is not. By instead pretty printing such a case as∀ (_ : A), q
, then, in addition to reducing surprise, we get strictly more information since we can tell from the_
that this is non-dependent and from the∀
thatA
is not a Prop. Since knowing when a pi type is non-dependent is useful, we go ahead and generalize this_
feature to all pi types with non-explicit binders -- the ones with explicit binders already hide the binder name since they pretty print usingA → B
notation.