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.236.14.99 with SMTP id c63mr8353378yhc.40.1407600703478; Sat, 09 Aug 2014 09:11:43 -0700 (PDT) X-Received: by 10.140.87.67 with SMTP id q61mr398910qgd.1.1407600703461; Sat, 09 Aug 2014 09:11:43 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!v10no5724518qac.1!news-out.google.com!j6ni34691qas.0!nntp.google.com!v10no5724513qac.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 9 Aug 2014 09:11:43 -0700 (PDT) In-Reply-To: <2extr7bydwfw.tcda12f9xnq9.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.108.152.51; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S NNTP-Posting-Host: 213.108.152.51 References: <932kntuq5rrr.8sumwibqrufn.dlg@40tude.net> <1ohy7vnbntskq$.h139ov04mlxu$.dlg@40tude.net> <536e35d6-f1de-4917-9300-26d78686eaf2@googlegroups.com> <1w3wuhu3d4nxi$.qluzbi0gtlxx$.dlg@40tude.net> <2extr7bydwfw.tcda12f9xnq9.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4a3996f3-666e-404a-ad8b-ff1832751787@googlegroups.com> Subject: Re: A bad counterintuitive behaviour of Ada about OO From: Maciej Sobczak Injection-Date: Sat, 09 Aug 2014 16:11:43 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.dca.giganews.com comp.lang.ada:188313 Date: 2014-08-09T09:11:43-07:00 List-Id: On Friday, August 8, 2014 3:22:56 PM UTC+2, Dmitry A. Kazakov wrote: > >> I still do not understand the example. > > > http://en.wikipedia.org/wiki/Covariant_return_type > > type A is tagged null record; > function getFoo return A; Wrong. getFoo should have a factory as a parameter (in the Wikipedia example this is hidden as "this" parameter). More complete example would be: package Products is type A is tagged null record; type B is new A with null record; end Products; package Factories is type A_Factory is tagged null record; function Make (AF : in A_Factory) return Products.A; type B_Factory is tagged null record; overriding function Make (BF : in B_Factory) return Products.B; end Factories; and GNAT says: subprogram "Make" is not overriding not type conformant with declaration at line XXX return type does not match As Randy pointed out, this cannot work in Ada. It's not even a matter of "fixing" something. > No dispatch, no covariance. Feel free to make up your own definitions. > If you are in the hierarchy of the factory > type, there cannot be any covariance in an unrelated hierarchy. This is *exactly* the definition of covariance, at least the one I know: http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29#Covariant_method_return_type > The only case where this may happen is parallel type hierarchies when two > types are inherited synchronously, e.g. > > type Object is tagged ... > type Handle is tagged ... > > function Access (X : Handle_To_Object) return Object; > > type New_Object is new Object with ... > > must produce > > type New_Handle is new Handle with ... > > and > > function Access (X : New_Handle) return New_Object; Yes. > No OOPL I know can handle this. Have you heard about those niche and unpopular languages like C++ and Java? ;-) -- Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com