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

Relative precedence of -. and ** #3414

Closed
vicuna opened this issue Jan 2, 2005 · 4 comments
Closed

Relative precedence of -. and ** #3414

vicuna opened this issue Jan 2, 2005 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Jan 2, 2005

Original bug ID: 3414
Reporter: administrator
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2016-12-07T10:37:11Z)
Resolution: won't fix
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Tags: patch
Monitored by: @hcarty @Chris00

Bug description

Full_Name: Christophe TROESTLER
Version: 3.08.2
OS: GNU/Linux
Submission from: ppp-62-235-157-155.tiscali.be (62.235.157.155)

It would be nice that -. and ** behave like in math. Specifically,

let x = 3. in
-. x**2.

sould return -9. (i.e. be parsed as -. (x**2.)) rather than the current 9.
(because it is seen as (-. x)**2.). The same therefore should also hold for
-.3.**2. and -3.**2. (while it is more debatable for the latter as -3. can be
seen as a constant...).

Best regards,
Christophe

File attachments

@vicuna
Copy link
Author

vicuna commented Aug 20, 2013

Comment author: @Chris00

Tentative patch attached. Hope you are happy with it — this issue has been opened for a long time.

@vicuna
Copy link
Author

vicuna commented Sep 3, 2013

Comment author: @damiendoligez

A general remark: we are very weary of changing the grammar because it's hard to tell how many programs this will break. In this particular case, the typechecker will not help at all in tracking the change, so programs will just start returning the wrong result without any hint of what is wrong.

I think it's pretty unlikely that we will ever dare to make this change.

@vicuna
Copy link
Author

vicuna commented Jul 26, 2014

Comment author: @Chris00

Patch updated against the current trunk.
#2

@vicuna
Copy link
Author

vicuna commented Dec 13, 2014

Comment author: @Chris00

Since you are wary of making such a change #2 (comment), how about issuing a warning when the construction -. xy is encountered without parentheses (i.e. not -. (xy)) — possibly telling the author to make their voice heard on this issue.

I think it is pretty bad that OCaml is a language that does not respect the universally adopted mathematical priorities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants