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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,21960280f1d61e84 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!uucp.gnuu.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: How come Ada isn't more popular? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1169531612.200010.153120@38g2000cwa.googlegroups.com> <1mahvxskejxe1$.tx7bjdqyo2oj$.dlg@40tude.net> <2tfy9vgph3.fsf@hod.lan.m-e-leypold.de> <1g7m33bys8v4p.6p9cpsh3k031$.dlg@40tude.net> <14hm72xd3b0bq$.axktv523vay8$.dlg@40tude.net> <4zwt33xm4b.fsf@hod.lan.m-e-leypold.de> <1j7neot6h1udi$.14vp2aos6z9l8.dlg@40tude.net> <1170347180.14376.104.camel@localhost.localdomain> <1nxunq6pci4r1$.1nnigcjicppwy.dlg@40tude.net> Date: Sat, 3 Feb 2007 10:45:26 +0100 Message-ID: <11g5kv93fm3ua.1p5hykfsdax5l$.dlg@40tude.net> NNTP-Posting-Date: 03 Feb 2007 10:45:10 CET NNTP-Posting-Host: 7fb5f73f.newsspool2.arcor-online.net X-Trace: DXC=Pb^CkMC04JUHigV@eW57PQA9EHlD;3YcR4Fo<]lROoRQFl8W>\BH3YR?S4OKB_jT_QDNcfSJ;bb[UIRnRBaCd On Fri, 02 Feb 2007 13:34:21 +0100, Markus E Leypold wrote: > "Dmitry A. Kazakov" writes: > >> Sure you can: >> >> type Additive is abstract; -- Should be enough for an interface >> function "+" (A, B : Additive) return Additive is abstract; >> >> Here I am not sure about "increment" variable, because it is not >> initialized. Anyway: >> >> function Increment return Additive is abstract; >> -- Better be getter/setter pair. Unfortunately Ada does not have >> -- "abstract variable interface" it should have >> >> function Inc (Arg : Additive'Class) return Additive'Class is >> begin >> return Increment + Arg; >> end Inc; >> >> There is a very simple rule for all this: >> >> 1. Formal generic subroutines -> abstract primitive operations >> 2. Subroutines in the body -> class-wide operations. > > So you derive from Additive to get a specific implementation? > > Like > > type Vector is Additive with ...; > type CountVal is Additive with ...; > > Right? But then, you should note that with > > C: Countval; > > Inc(C). > > returns an 'Additive', not a 'CountVal'. No, it does Additive'Class! Thus, no problem. (note that the goal was polymorphic Inc, if you wanted it covariant that would automatically exclude polymorphism) > That is one problem. The > other is of course that Increment is not initialized. This is exactly > what generics are here to solve. As it was in Georg's example. But with inheritance covariant Increment would be required to be overridden (praised be Ada). So an initialization will be enforced anyway. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de