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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9ce095aba33fe8d0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Negative float problem Date: 02 Nov 2005 08:24:29 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1130351574.313991.229420@g14g2000cwa.googlegroups.com> <10mspnley7gzu$.1swtj67sv0ldr$.dlg@40tude.net> <43677dec$1_1@glkas0286.greenlnk.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1130937869 14110 192.74.137.71 (2 Nov 2005 13:24:29 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 2 Nov 2005 13:24:29 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:6118 Date: 2005-11-02T08:24:29-05:00 List-Id: Martin Dowie writes: > Robert A Duff wrote: > > I wasn't talking about the difference between enums in C++ versus Ada. > > I was talking about the difference in overload resolution rules. > > Namely that the result type of a function call is used to resolve > > in Ada, but not in C++. (And by the way Ada has this weird idea > > that enum lits are functions.) > > I actually rather like this 'weird idea' - it can be very handy with > generics: > > generic > type Foo is private; > with function Is_A_Bar (F : Foo) return Boolean; > procedure Generic_Do_Something (F : Foo); > > procedure Do_Something is > new Generic_Do_Something (Integer, True); > -- Integers are always Bars > > procedure Do_Something is > new Generic_Do_Something (Float, False); > -- Floats are never Bars > > procedure Do_Something is > new Generic_Do_Something (My_Type, Is_This_A_Bar); > -- My_Types are sometimes Bars Except that the above is illegal. ;-) True is a _parameterless_ function, and does not match Is_A_Bar. Anyway, this rule is a kludge, because it doesn't work for other things (constants come to mind). For example: type Color is (Red, Orange); should have similar semantics to: type Color is private; Red: constant Color; Orange: constant Color; private type Color is range ...; Red: constant Color := 0; Orange: constant Color := 1; because conceptually, they are similar. People think of enums as a restricted form of integers, not as functions. And if they can be passed to generic formal functions, then _any_ expression should allow that functionality. You should be able to switch back and forth between integers and enums without arbitrary rules getting in the way. (There might be good reasons to use integers, for example -- you want to interface to some other language. But when you switch to integers, you have to change the names of all the overloaded literals.) Besides, allowing False to be passed to a generic formal function causes quite a bit of implementation difficulty -- far more than it's worth. - Bob