From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5EF127FD5B for ; Thu, 3 Dec 2015 11:02:52 +0100 (CET) IronPort-PHdr: 9a23:k9taLh3uUe4aE+QhsmDT+DRfVm0co7zxezQtwd8ZsegeLvad9pjvdHbS+e9qxAeQG96LtbQc16GO4+jJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6MyZzrnLjis7ToICx2xxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP5Xz247bXianhL7+9vitMU7q3cYk7sb+sVBSaT3ebgjBfwdVWx+cjN92Mq+mhTZQUO0+nwYSmAflBwAVwnD4hbSUZrrvm7hqu15wCyTO8uwQb1iChq46KI+cwPhjiYcMzcnuEjNlsF1j6Nd6EaovQByxo3VZqmaMfN/euXWetZMFjkJZdpYSyEUWtD0VIAIFedUeL8A94Q= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=artemkin@gmail.com; spf=Pass smtp.mailfrom=artemkin@gmail.com; spf=None smtp.helo=postmaster@mail-lf0-f46.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of artemkin@gmail.com) identity=pra; client-ip=209.85.215.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="artemkin@gmail.com"; x-sender="artemkin@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of artemkin@gmail.com designates 209.85.215.46 as permitted sender) identity=mailfrom; client-ip=209.85.215.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="artemkin@gmail.com"; x-sender="artemkin@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lf0-f46.google.com) identity=helo; client-ip=209.85.215.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="artemkin@gmail.com"; x-sender="postmaster@mail-lf0-f46.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AOBQCwEmBWmy7XVdFeGQEBAQEPAQEBAYI+azRuBq4GhQiDA4czgWIjhSJKAoFCBzkTAQEBAQEBAQEQAQEBAQEGCwsJIS6CLYIIAQEBAQEBEhEdARQHHQEDAQsGAwILAx8VAgIiAREBBQEcBhMJGYd3AQMKCA2TJY9OgTE+MYtIgWqCeYcpChknDVaDbwEBAQEBAQEDAQEBAQEBARYBBQ6LRIRmNIJdgUQFh0+GS4hGhSyGGoF0giSYfhIkgRcREgKCQiOBYjk0AQGFagEBAQ X-IPAS-Result: A0AOBQCwEmBWmy7XVdFeGQEBAQEPAQEBAYI+azRuBq4GhQiDA4czgWIjhSJKAoFCBzkTAQEBAQEBAQEQAQEBAQEGCwsJIS6CLYIIAQEBAQEBEhEdARQHHQEDAQsGAwILAx8VAgIiAREBBQEcBhMJGYd3AQMKCA2TJY9OgTE+MYtIgWqCeYcpChknDVaDbwEBAQEBAQEDAQEBAQEBARYBBQ6LRIRmNIJdgUQFh0+GS4hGhSyGGoF0giSYfhIkgRcREgKCQiOBYjk0AQGFagEBAQ X-IronPort-AV: E=Sophos;i="5.20,377,1444687200"; d="scan'208";a="156021482" Received: from mail-lf0-f46.google.com ([209.85.215.46]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 03 Dec 2015 11:02:50 +0100 Received: by lfaz4 with SMTP id z4so85480565lfa.0 for ; Thu, 03 Dec 2015 02:02:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Gwow/nb36IP9tyuYNSY279gUgSbNnLEl/42siPn8ZBw=; b=BW5H0ACQlDUdsfyVU71V1d5osHIJu5cFp5f9v8uEHQvL2OHXQ7bCmEJgvd4amT4w2g QaXt0HWMXiBfKGpPVHBIZf2YNYKFXihF8bbDmmliCZSdpXvyjAJ2utcYaAwt5+Y4ZfhT 2NTh2LEMOKJQuc0tcrwdtyKgMkhYnQRx3Zyx76Q9nuWtlGZHsePGcw9xxyMh2fgZQ7IH B7IfZFneTC+xZ0qS2nDzVRZ5vLYQbo8hQx5rKwrk4fudRtHBqyp/iKKABJ+NpVfumvtO 1BPW0JCKxNYPiJm6Y0hoxxQu2iw/2OVzcD/ZbBMN6ASgsrtM6IUZhKQMAyBOuQzW7QIg Ed0A== MIME-Version: 1.0 X-Received: by 10.25.30.5 with SMTP id e5mr4572921lfe.48.1449136970069; Thu, 03 Dec 2015 02:02:50 -0800 (PST) Received: by 10.113.3.70 with HTTP; Thu, 3 Dec 2015 02:02:50 -0800 (PST) In-Reply-To: <1449089348.15053.10.camel@zotac> References: <1449089348.15053.10.camel@zotac> Date: Thu, 3 Dec 2015 14:02:50 +0400 Message-ID: From: Stanislav Artemkin To: Gerd Stolpmann Cc: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a113fa5d05500070525fb7efd Subject: Re: [Caml-list] Unary negation parsing --001a113fa5d05500070525fb7efd Content-Type: text/plain; charset=UTF-8 > 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 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 > ------------------------------------------------------------ > --001a113fa5d05500070525fb7efd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
> In short, the l= iteral maxint+1 is accepted because minint=3D-(maxint+1),
> and we don'= t have negative literals.

It looks strange that=C2=A04611686018427387904 is accepted (defect?), and OCaml actually define= s negative numeric literals according to=C2=A0http://caml.inria.fr/pub/docs/manual-oca= ml/lex.html

On the contrary, F# doesn't hav= e negative numeric literals, but defines a post-filtering of adjacent=C2=A0= prefix tokens in 3.8.1.=C2=A0See=C2=A0http://fsharp.org/specs= /language-spec/3.0/FSharpSpec-3.0-final.pdf#page=3D28
=
Thanks

On Thu, Dec 3, 2015 at 12:49 AM, Gerd Stolpmann <info@gerd-= stolpmann.de> wrote:
Thinki= ng that this is a mostly aesthetic question, with one little
exception:

# max_int;;
- : int =3D 4611686018427387903
# -4611686018427387904;;
- : int =3D -4611686018427387904
# 4611686018427387904;;
- : int =3D -4611686018427387904
# 4611686018427387905;;
Error: Integer literal exceeds the range of representable integers of
type int

In short, the literal maxint+1 is accepted because minint=3D-(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<= br> 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<= br> > parsing
> (htt= p://stackoverflow.com/questions/34044873/passing-negative-integer-to-a-func= tion-in-ocaml):
>
>
> let f x =3D 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 whit= espace 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=C2=A0 =C2=A0 gerd@gerd-stolpmann.de
My OCaml site:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 http://www.camlcity.org<= br> Contact details:=C2=A0 =C2=A0 =C2=A0 =C2=A0 http://www.camlcity.= org/contact.html
Company homepage:=C2=A0 =C2=A0 =C2=A0 =C2=A0http://www.gerd-stolpmann.de=
------------------------------------------------------------

--001a113fa5d05500070525fb7efd--