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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,5a88548f1bcf3510 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Received: by 10.180.91.231 with SMTP id ch7mr1087765wib.1.1353057965693; Fri, 16 Nov 2012 01:26:05 -0800 (PST) Path: q13ni312926wii.0!nntp.google.com!feeder1.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!216.40.29.245.MISMATCH!novia!news-hub.siol.net!news1.t-com.hr!newsfeed.CARNet.hr!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Overring function and its returned type Date: Fri, 09 Nov 2012 22:10:05 +0100 Organization: Ada @ Home Message-ID: References: <97a6946f-a707-4dd3-872b-9e851fcf9462@googlegroups.com> NNTP-Posting-Host: aWaWeUaBdaj2Zzc04J1v5A.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.02 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-11-09T22:10:05+01:00 List-Id: Le Fri, 09 Nov 2012 20:57:21 +0100, a =C3=A9crit= : > More generally, you are talking about 'covariant return types', which = is = > a feature only a handful of languages support (notably C++). May be (I feel to remember this, while unsure). > IMHO, i don't really see the need for it; a type is either a child (a= nd = > matches the parent, as in P3) or it doesn't and it's not (as in P2). = = > The whole point is to use the abstract parent classwide type = > exclusively, so I never saw the need to tinker around with the concret= e = > child types (i would be interested in a real life scenario in which yo= u = > would want this construct) I won't post here the real thing, I'm only OK to post samples and = snippets. You will have to trust me when I say it make sense (so much, I= = wrote things straight away, without suspecting it could be rejected). = Still, to give you an idea, imagine this: In `P3` spec, replace the definition of `F` with this one: overriding function F (E : T) return P1.R'Class with Post'Class =3D> F'Result in R'Class; Then, a sample use case would look like this: A : P3.T; B : P3.R'Class :=3D P3.R'Class (A.F); That looks weird, as much weird as writing something like this: type IST is new Integer range 1 .. 10; function F return Integer with Post =3D> F'Result in 1 .. 10; function F return Integer is begin return 1; end; D : IST :=3D IST (F); Reading the above, one may say =E2=80=9Cthat's silly, if you know the re= turned = type, just specify it in the declaration, and this would additionally = avoid a cumbersome checked conversion at every call place=E2=80=9D. That= 's exactly = what I feel adding a postcondition to `F` just to state what the returne= d = type is, and adding a conversion at the call place. My words may looks a= = too hard, but I would say I would expect Ada to not require to specify = types via pre/post condition, but in signature instead. I will also try to workaround with an overloading instead of an = overriding, but I'm afraid of getting into a mess with this solution. Wi= ll = choose which cause the less troubles, and although the = postcondition+conversion solution looks like bloat, I believe that's sti= ll = the safest. I will still try both to really get an idea=E2=80=A6 -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity