Skip to content
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

notations are not printed correctly #358

Open
1 task
JasonGross opened this issue Mar 19, 2021 · 3 comments
Open
1 task

notations are not printed correctly #358

JasonGross opened this issue Mar 19, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@JasonGross
Copy link

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

class ArrSort (α : Sort u1) (cell_level : Nat) where
  Arr : α → α → Sort u2
class Arr (α : Sort u1) (γ : Sort u2) (cell_level : Nat) where
  Arr : α → α → γ
infix:70 " ~> " => Arr.Arr (cell_level := 1)
infix:70 " ≈> " => Arr.Arr (cell_level := 2)
@[defaultInstance, reducible, inline]
instance ArrOfArrSort {α : Sort _} {cell_level} [ArrSort α cell_level] : Arr α (Sort _) cell_level := { Arr := ArrSort.Arr cell_leve\
l }
namespace Preorder
  structure Preorder where
    Obj : Type u0
    Arr : Obj → Obj → Type u1
  def Unit : Preorder.{u0,u1} := { Obj := ULift _root_.Unit , Arr := λ _ _ => ULift _root_.Unit }
  instance OfNat1 : OfNat Preorder.Preorder (nat_lit 1) := { ofNat := Unit }
  structure Fun (A B : Preorder.{u0,u1}) where
  @[inline, reducible] scoped instance as_1cell.has_arr : ArrSort Preorder 2 := { Arr := Fun }
  structure Fun2 {A B : Preorder.{u0,u1}} (f g : Fun A B) where
  @[inline, reducible] scoped instance as_1cell.has_arr2 {A B : Preorder.{u0,u1}} : _root_.ArrSort (Fun A B) 3 := { Arr := Fun2 }
end Preorder
namespace Procat
structure Procat where
  Obj : Type u0
  Arr : Obj → Obj → Preorder.Preorder.{u1,u2}
@[inline, reducible] scoped instance internal.has_arr {C : Procat} : Arr C.Obj Preorder.Preorder 1 := { Arr := C.Arr }
namespace internal
open Preorder.as_1cell
scoped infix :70 (priority:=high) " ~> " => _root_.Arr.Arr (self:=has_arr)
def compose (C : Procat) {a b c : C.Obj} (f : 1 ≈> (a ~> b)) (g : 1 ≈> (b ~> c)) : 1 ≈> (a ~> c)
  := by { done }
/-
Messages (1)
29:10:
unsolved goals
C : Procat
a b c : C.Obj
f : Arr.Arr 2 1 (Arr.Arr 1 a b)
g : Arr.Arr 2 1 (Arr.Arr 1 b c)
⊢ Arr.Arr 2 1 (Arr.Arr 1 a c)
-/

Why is it that the parsing works fine, but the notations are not reprinted?

Versions

$ lean --version

Lean (version 4.0.0-nightly-2021-03-19, commit 1af02dc, Release)

$ uname -a
Linux JasonGross-X1 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
$ cmd.exe /C ver
'\\wsl$\Ubuntu\home\jgross\Documents\GitHub\lean-tools'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

Microsoft Windows [Version 10.0.19041.804]
@Kha
Copy link
Member

Kha commented Mar 21, 2021

This is the current heuristic for deriving a pretty printer from a notation:

/-- Try to derive a `SimpleDelab` from a notation.
The notation must be of the form `notation ... => c var_1 ... var_n`
where `c` is a declaration in the current scope and the `var_i` are a permutation of the LHS vars. -/

It does not yet handle constant arguments like (cell_level := 1)

@Kha Kha added the enhancement New feature or request label Mar 23, 2021
@leodemoura leodemoura added closing soon This issue will be closed soon (<1 month) as it is missing essential features. and removed closing soon This issue will be closed soon (<1 month) as it is missing essential features. labels Mar 20, 2022
@leodemoura
Copy link
Member

@Kha Will this ever be fixed? The appUnexpander works at the Syntax level. To make this kind of example work it seems we would need to do it at the "delaborator" level.
I think what is missing is a "warning" message telling the user that pretty-print support was not generated for the given notation declaration. Users could avoid the "warning" by using a new (parser_only := true) parameter at notation.

@Kha
Copy link
Member

Kha commented Jul 29, 2022

@leodemoura In theory, notation could synthesize delabs for common cases (where no notation parameter is used as a binder) such as this one. The warning still sounds good though. I would suggest simple (print := false)/(parse := false) parameters, with the latter being useful in cases such as https://github.com/larsk21/iris-lean/blob/master/src/Iris/Proofmode/Display.lean.

ChrisHughes24 pushed a commit to ChrisHughes24/lean4 that referenced this issue Dec 2, 2022
The `#help` command can be used to list all definitions in a variety of extensible aspects of lean.

* `#help option` lists options (used in `set_option myOption`)
* `#help attr` lists attributes (used in `@[myAttr] def foo := ...`)
* `#help cats` lists syntax categories (like `term`, `tactic`, `stx` etc)
* `#help cat C` lists elements of syntax category C
  * `#help term`, `#help tactic`, `#help conv` are shorthand for `#help cat term` etc.

All forms take an optional identifier to narrow the search; for example `#help option pp` shows
only `pp.*` options.

This command depends on several unmerged lean core PRs to add the necessary APIs to support these queries:

* [x] Depends on leanprover#1384 (to get docstrings for attributes)
* [x] Depends on leanprover#1391 (polyfill provided)
* [x] Depends on leanprover#1392 (to enumerate syntax in a syntax category, without which `#help cat` doesn't work at all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants