* [Caml-list] Unary negation parsing @ 2015-12-02 18:59 Stanislav Artemkin 2015-12-02 20:49 ` Gerd Stolpmann 2015-12-02 21:21 ` Mr. Herr 0 siblings, 2 replies; 4+ messages in thread From: Stanislav Artemkin @ 2015-12-02 18:59 UTC (permalink / raw) To: Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 686 bytes --] Hi all, I've just stumbled upon yet another question about unary negation parsing ( http://stackoverflow.com/questions/34044873/passing-negative-integer-to-a-function-in-ocaml ): let f x = x + 1 in f -1 is not valid in OCaml. I'm just wondering why this issue is still not addressed in the parser? For example, F# parses "f -1" as unary negation, but "f - 1" and "f-1" as binary operator. It looks a bit tricky (as whitespace is taken into account), but feels so natural when writing code. Is there any reason we can't have the same in OCaml? PS. I understand that it may break existing code, but it should be solvable by a compiler option similar to -safe-string etc. Thank you [-- Attachment #2: Type: text/html, Size: 1047 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Unary negation parsing 2015-12-02 18:59 [Caml-list] Unary negation parsing Stanislav Artemkin @ 2015-12-02 20:49 ` Gerd Stolpmann 2015-12-03 10:02 ` Stanislav Artemkin 2015-12-02 21:21 ` Mr. Herr 1 sibling, 1 reply; 4+ messages in thread From: Gerd Stolpmann @ 2015-12-02 20:49 UTC (permalink / raw) To: Stanislav Artemkin; +Cc: Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 2016 bytes --] Thinking that this is a mostly aesthetic question, with one little exception: # max_int;; - : int = 4611686018427387903 # -4611686018427387904;; - : int = -4611686018427387904 # 4611686018427387904;; - : int = -4611686018427387904 # 4611686018427387905;; Error: Integer literal exceeds the range of representable integers of type int In short, the literal maxint+1 is accepted because minint=-(maxint+1), and we don't have negative literals. However, the question is whether it is worth the trouble changing it. As you mention -safe-string, I just went through a large library and updated it, and it was far from trivial (needed GADTs) and a lot of work (something like 30 hours, really). I'm still skeptical whether changes of this kind get you a real benefit. Gerd Am Mittwoch, den 02.12.2015, 22:59 +0400 schrieb Stanislav Artemkin: > Hi all, > > > I've just stumbled upon yet another question about unary negation > parsing > (http://stackoverflow.com/questions/34044873/passing-negative-integer-to-a-function-in-ocaml): > > > let f x = x + 1 in > f -1 > > > is not valid in OCaml. > > > I'm just wondering why this issue is still not addressed in the > parser? For example, F# parses "f -1" as unary negation, but "f - 1" > and "f-1" as binary operator. It looks a bit tricky (as whitespace is > taken into account), but feels so natural when writing code. > > > Is there any reason we can't have the same in OCaml? > > > PS. I understand that it may break existing code, but it should be > solvable by a compiler option similar to -safe-string etc. > > > Thank you > > -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------ [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Unary negation parsing 2015-12-02 20:49 ` Gerd Stolpmann @ 2015-12-03 10:02 ` Stanislav Artemkin 0 siblings, 0 replies; 4+ messages in thread From: Stanislav Artemkin @ 2015-12-03 10:02 UTC (permalink / raw) To: Gerd Stolpmann; +Cc: Ocaml Mailing List [-- Attachment #1: Type: text/plain, Size: 2652 bytes --] > In short, the literal maxint+1 is accepted because minint=-(maxint+1), > and we don't have negative literals. It looks strange that 4611686018427387904 is accepted (defect?), and OCaml actually defines negative numeric literals according to http://caml.inria.fr/pub/docs/manual-ocaml/lex.html On the contrary, F# doesn't have negative numeric literals, but defines a post-filtering of adjacent prefix tokens in 3.8.1. See http://fsharp.org/specs/language-spec/3.0/FSharpSpec-3.0-final.pdf#page=28 Thanks On Thu, Dec 3, 2015 at 12:49 AM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote: > Thinking that this is a mostly aesthetic question, with one little > exception: > > # max_int;; > - : int = 4611686018427387903 > # -4611686018427387904;; > - : int = -4611686018427387904 > # 4611686018427387904;; > - : int = -4611686018427387904 > # 4611686018427387905;; > Error: Integer literal exceeds the range of representable integers of > type int > > In short, the literal maxint+1 is accepted because minint=-(maxint+1), > and we don't have negative literals. > > However, the question is whether it is worth the trouble changing it. As > you mention -safe-string, I just went through a large library and > updated it, and it was far from trivial (needed GADTs) and a lot of work > (something like 30 hours, really). I'm still skeptical whether changes > of this kind get you a real benefit. > > Gerd > > > Am Mittwoch, den 02.12.2015, 22:59 +0400 schrieb Stanislav Artemkin: > > Hi all, > > > > > > I've just stumbled upon yet another question about unary negation > > parsing > > ( > http://stackoverflow.com/questions/34044873/passing-negative-integer-to-a-function-in-ocaml > ): > > > > > > let f x = x + 1 in > > f -1 > > > > > > is not valid in OCaml. > > > > > > I'm just wondering why this issue is still not addressed in the > > parser? For example, F# parses "f -1" as unary negation, but "f - 1" > > and "f-1" as binary operator. It looks a bit tricky (as whitespace is > > taken into account), but feels so natural when writing code. > > > > > > Is there any reason we can't have the same in OCaml? > > > > > > PS. I understand that it may break existing code, but it should be > > solvable by a compiler option similar to -safe-string etc. > > > > > > Thank you > > > > > > -- > ------------------------------------------------------------ > Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de > My OCaml site: http://www.camlcity.org > Contact details: http://www.camlcity.org/contact.html > Company homepage: http://www.gerd-stolpmann.de > ------------------------------------------------------------ > [-- Attachment #2: Type: text/html, Size: 4326 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Unary negation parsing 2015-12-02 18:59 [Caml-list] Unary negation parsing Stanislav Artemkin 2015-12-02 20:49 ` Gerd Stolpmann @ 2015-12-02 21:21 ` Mr. Herr 1 sibling, 0 replies; 4+ messages in thread From: Mr. Herr @ 2015-12-02 21:21 UTC (permalink / raw) To: caml-list [-- Attachment #1: Type: text/plain, Size: 917 bytes --] On 02.12.2015 19:59, Stanislav Artemkin wrote: > Hi all, > > I've just stumbled upon yet another question about unary negation parsing > (http://stackoverflow.com/questions/34044873/passing-negative-integer-to-a-function-in-ocaml): > > let f x = x + 1 in > f -1 > > is not valid in OCaml. > > I'm just wondering why this issue is still not addressed in the parser? For > example, F# parses "f -1" as unary negation, but "f - 1" and "f-1" as binary > operator. It looks a bit tricky (as whitespace is taken into account), but feels so > natural when writing code. > > Is there any reason we can't have the same in OCaml? > > PS. I understand that it may break existing code, but it should be solvable by a > compiler option similar to -safe-string etc. > I think this is a non-issue, and it is easily explained to every beginner. And you say yourself: ... tricky .. whitespace ... may break existing code ... /Str. [-- Attachment #2: Type: text/html, Size: 1873 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-12-03 10:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-12-02 18:59 [Caml-list] Unary negation parsing Stanislav Artemkin 2015-12-02 20:49 ` Gerd Stolpmann 2015-12-03 10:02 ` Stanislav Artemkin 2015-12-02 21:21 ` Mr. Herr
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox