The `delabConstWithSignature` delaborator is responsible for pretty printing constants with a declaration-like signature, with binders, a colon, and a type. This is used by the `#check` command when it is given just an identifier. It used to accumulate binders from pi types indiscriminately, but this led to unfriendly behavior. For example, `#check String.append` would give ``` String.append (a✝ : String) (a✝¹ : String) : String ``` with inaccessible names. These appear because `String.append` is defined using patterns, so it never names these parameters. Now the delaborator stops accumulating binders once it reaches an inaccessible name, and for example `#check String.append` now gives ``` String.append : String → String → String ``` We do not synthesize names for the sake of enabling binder syntax because the binder names are part of the API of a function — one can use `(arg := ...)` syntax to pass arguments by name. The delaborator also now stops accumulating binders once it reaches a parameter with a name already seen before — we then rely on the main delaborator to provide that parameter with a fresh name when pretty printing the pi type. As a special case, instance parameters with inaccessible names are included as binders, pretty printing like `[LT α]`, rather than relegating them (and all the remaining parameters) to after the colon. It would be more accurate to pretty print this as `[inst✝ : LT α]`, but we make the simplifying assumption that such instance parameters are generally used via typeclass inference. Likely `inst✝` would not directly appear in pretty printer output, and even if it appears in a hover, users can likely figure out what is going on. (We may consider making such `inst✝` variables pretty print as `‹LT α›` or `infer_instance` in the future, to make this more consistent.) Something we note here is that we do not do anything to make sure parameters that can be used as named arguments actually appear named after the colon (nor do we assure that the names are the correct names). For example, one sees `foo : String → String → String` rather than `foo : String → (baz : String) → String`. We can investigate this later if it is wanted. We also give `delabConstWithSignature` a `universes` flag to enable turning off pretty printing universe levels parameters. Closes #2846
14 lines
645 B
Text
14 lines
645 B
Text
f Nat 5 : Nat
|
||
g 5 : Nat
|
||
Ex1.f (α : Type) [Add α] (a : α) : α
|
||
Ex1.g {α : Type} (b : α) : α
|
||
f Nat 5 : Nat
|
||
g 5 : Nat
|
||
Ex2.f (α : Type) (a : α) : α
|
||
Ex2.g {β : Type} (b : β) : β
|
||
varBinderUpdate.lean:25:10-25:11: error: redundant binder annotation update
|
||
Ex3.g (α : Type) (f : α → α) (a : α) : α
|
||
Ex3.h (α : Type) {f : α → α} (a : α) : α
|
||
g Nat Bool 10 "hello" true : Nat × String × Bool
|
||
varBinderUpdate.lean:51:10-51:11: error: cannot change the binder annotation of the previously declared local instance `i`
|
||
varBinderUpdate.lean:59:10-59:11: error: cannot update binder annotation of variables with default values/tactics
|