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,c84654714c2f5945 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: GNAT GPL Edition - on the plus side Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.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: <1u927xnbmsfw1$.1xg4jk31952ts$.dlg@40tude.net> Date: Sat, 15 Oct 2005 18:14:08 +0200 Message-ID: NNTP-Posting-Date: 15 Oct 2005 18:13:54 MEST NNTP-Posting-Host: ddea21de.newsread4.arcor-online.net X-Trace: DXC=Fhi;hCfZZ3PUEj^fn36YV^:ejgIfPPldTjW\KbG]kaMX;F:^k\0:_XU30dM_jH6SeTWRXZ37ga[7ZjTA67ckJ=XUIT8A@YAM12_ X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:5707 Date: 2005-10-15T18:13:54+02:00 List-Id: On 15 Oct 2005 10:45:39 -0400, Robert A Duff wrote: > "Randy Brukardt" writes: > >> "Dmitry A. Kazakov" wrote in message >> news:b4p2ksjzkv4m.6ghazx68f8js.dlg@40tude.net... >>> Anyway, generics and templates are inherently a mess, but that is another >>> story. (:-)) >> >> Perhaps because we haven't seen any crying need. I, for one would prefer to >> reduce the need for generics than to pile on more features. Absolutely. >> You have said in >> the past that generics are unnecessary with good OOP, and I tend to agree. > > Could either or both of you explain why generics are unnecessary > (i.e. what changes to Ada's OOP would make them unnecessary). > > In particular, I want to be able to have a container type tied to the > type of its elements (perhaps class-wide). If I have a "sequence of > T'Class", and I put something in it, and take it back out, I don't want > to lose the fact that this element is somewhere in the T'Class > hierarchy. Generics seem to work well for that. > > How would you define the "sequence" abstraction without generics? I am not sure I have understood what you meant, but it seems to me that you want containers constrained to a particular type. I see no great problem here. Already Ada 83 handled some constraints without any generics: type String is ...; subtype Punch_Card is String (1..80); -- Range constraint We could extend this idea allowing type constraints: type Container (...) is array (...) of Element'Class; type Foo is new Element ...; subtype Foo_Container is Container (some sugar to constrain Element'Class to Foo'Class); As an additional advantage over generics Foo_Container can be used in all subprograms expecting Container'Class. Otherwise, Foo_Container can be declared as: type Foo_Container is new Container (some sugar to constrain Element'Class to Foo'Class); here "is new" has old, Ada 83 sense: create an anonymous copy of Container, make a constrained subtype and name it Foo_Container. [It was very unfortunate that Ada 95 used "is new" for inheritance.] Generally, I think that in all cases when one type is composed out of some other types (be it a record, array, access etc type) there should be a unified language-defined way to create constrained subtypes. Maybe explicitly via discriminants: type Ptr (Target : T'Tag) is access T'Class (Target); subtype Ptr_To_A is Ptr (Target => A'Tag); Maybe implicitly assuming discriminats or attributes for constraints everywhere. I believe, this all is equivalent to having "type discriminants", which is pretty close to usual intent of a programmer using generics, though on a completely different basis. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de