From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.10.199 with SMTP id q7mr18703997qaq.7.1411753868213; Fri, 26 Sep 2014 10:51:08 -0700 (PDT) X-Received: by 10.50.66.179 with SMTP id g19mr539207igt.17.1411753868053; Fri, 26 Sep 2014 10:51:08 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!w8no354257qac.0!news-out.google.com!bc9ni657igb.0!nntp.google.com!a13no4079363igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 26 Sep 2014 10:51:07 -0700 (PDT) In-Reply-To: <98f0066e-4b5c-4b00-b811-dcbb13ed0fcf@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <98f0066e-4b5c-4b00-b811-dcbb13ed0fcf@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Integers and Mathematical Correctness From: Adam Beneschan Injection-Date: Fri, 26 Sep 2014 17:51:08 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:189181 Date: 2014-09-26T10:51:07-07:00 List-Id: On Friday, September 26, 2014 9:59:00 AM UTC-7, AdaMagica wrote: > On Friday, September 26, 2014 6:38:10 PM UTC+2, Niklas Holsti wrote: =20 > > False. Ada can overload operators on the result type, so you can very= =20 > > well add > > > > function "/" (Left, Right : Integer) return Rational; >=20 > > and have both"/" visible and used with in-fix notation. > > Nah, it's not that easy. The reason is that Integer is defined in Standar= d, which always has precedence for any use-clause. The precedence of use clauses is irrelevant. This (and other rules about v= isibility and hiding) are used when there are two homographs and the compil= er needs to decide which one is meant. Thus, if you have a type "Integer" = defined in Standard, and a type "Integer" defined in some USE'd package, I = think the one in Standard would hide the other one, as you say. However, functions are homographs only if they have the same name, same par= ameter types, and same return type. Thus, the function function "/" (Left, Right : Integer) return Integer; defined in Standard cannot hide the function function "/" (Left, Right : Integer) return Rational; defined somewhere else. The compiler uses the overloading rules, not the U= SE rules or any such visibility rules, to determine which one is meant. So= if use use / in a context where the result is Rational, it will work fine-= -the definition in Standard cannot hide it. If you use it in a context whe= re the compiler can't tell which one is meant, the expression is ambiguous-= -the rules about USE clauses and such will not help to make it unambiguous. =20 =20 > You need a separate integer type >=20 > type Whole is range ... > function "/" (Left, Right: Whole) return Rational; No, this is not necessary. Unless the compiler is faulty. -- Adam