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

bbv makes it impossible to use $ as a prefix printing notation without parentheses #5

Closed
JasonGross opened this issue May 7, 2018 · 15 comments

Comments

@JasonGross
Copy link
Contributor

JasonGross commented May 7, 2018

Word.v defines "$ x" to be a notation at level 0 (and similarly with #). This conflicts with the notations I want to use in fiat-crypto. Please put these notations in a Module (e.g., WordNotations) and do not export this module by default from any file.

@vmurali
Copy link
Contributor

vmurali commented May 7, 2018 via email

@andres-erbsen
Copy link
Contributor

Is there actually a good reason why $ should be at the extreme level of 0, as opposed to something like 10 (same as function application)? Since both of these are breaking changes, it may make sense to do them together.

@samuelgruetter
Copy link
Contributor

Also, some notations are in word_scope, while others don't have an explicit scope, is there any reason for this other than historical?
Not opening word_scope provides some protection from unwanted notations, but probably not what @JasonGross needs, because even if you don't open word_scope, the notations still define the level and associativity in an irreversible way, so they should really be in a separate module.

@samuelgruetter
Copy link
Contributor

@andres-erbsen if you put $ at level 10, you have to write f ($4) ($5) instead of f $4 $5, which I think is undesirable. Level 9 is the highest level where f $4 $5 still works. Do you have a particular other notation in mind which would benefit from changing the level of $?

@andres-erbsen
Copy link
Contributor

f $4 $5 sounds like an use case that I don't want to argue against, so feel free to pick any level below 10 or keep it at 0 as you wish. Overall, I think avoiding bringing in notations is a better approach than trying to make them compatible -- after all, Haskell people would probably want to put $ at level 100 or something like that to act as ( ... ) $ ( ... )...

@JasonGross
Copy link
Contributor Author

I would like to put it at level 9, x at level 10 for usage in fiat-crypto, so that it displays without the parentheses, which is incompatible both with at level 9 and with at level 10 (and with at level 0). This is why I want it to not be exported by default anywhere.

@samuelgruetter
Copy link
Contributor

What exactly do you mean by "displays without parentheses"? I can do the following, is this what you meant?

Definition word(sz: nat): Set. Admitted.
Definition natToWord (sz n : nat) : word sz. Admitted.


Notation "$ n" := (natToWord _ n) (at level 0, n at level 0, format "$ n") .

Definition f{sz}(a b c: word sz): word sz. Admitted.

Definition a: nat := 7.
Definition t: word 8 := f $a $5 $(3 + 4).

Print t. (* prints "f $a $5 $(3 + 4)" *)

Whereas currently, this would print as f $ (a) $ (5) $ (3 + 4). I think it would be nice to have $ without parentheses in Word.v too.

@JasonGross
Copy link
Contributor Author

Yes, that is what I meant. But, even with this change, I think that both # and $ should be in their own module and not exported by default.

@vmurali
Copy link
Contributor

vmurali commented May 8, 2018 via email

@samuelgruetter
Copy link
Contributor

Yes of course we should put the notations inside a module, I was just wondering whether we can get parenthesis-less $ in bbv too because I think that would be nice.

Moreover, it would also be nice if the lemmas in Word.v could still use $, to avoid big refactoring effort. Do you think it would be ok to have the following code inside Word.v? (As in, is $ isolated enough to not spoil what you or anyone else in the future wants to do?)

Module WordNotations.

Notation "$ n" := (natToWord _ n) (at level 0, n at level 0, format "$ n") .

(* more notations... *)

End WordNotations.

Import WordNotations. (* but not exported *)

(* lemmas happily using $ ... *)

@vmurali
Copy link
Contributor

vmurali commented May 8, 2018

I am fine with this. I believe it is similar to the notations in List.v.

@samuelgruetter
Copy link
Contributor

@JasonGross would you mind submitting a PR for this?

@vmurali
Copy link
Contributor

vmurali commented Jun 29, 2018

Bump. Can we get this done? I don't mind submitting a pull request for this.

@samuelgruetter
Copy link
Contributor

Yes, please submit a PR @vmurali!
I just merged #9, so you can have the "edit lock" for some time 😉

@JasonGross
Copy link
Contributor Author

Note also that putting # at level 0 breaks the infix # notation from the QArith stdlib module.

JasonGross added a commit to JasonGross/bbv that referenced this issue Jul 25, 2018
Also adjust the level of $n, see the discussion in mit-plv#5.

Closes mit-plv#5
JasonGross added a commit to JasonGross/bbv that referenced this issue Jul 25, 2018
Also adjust the level of $n, see the discussion in mit-plv#5.

We also move all of the level specifications to ReservedNotations.v.
This allows early detection of notation conflicts, as any file importing
bbv.ReservedNotations will observe all notation conflicts that can arise
from importing any file of bbv.

Closes mit-plv#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants