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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Generics vs. O-O? Date: Fri, 2 Aug 2013 10:11:32 +0200 Organization: cbb software GmbH Message-ID: <15qso6tlt3uf1.h45wqc019b00$.dlg@40tude.net> References: <6238c325-79c5-4537-ba55-2800110dc6df@googlegroups.com> <1wugpqyea6s39$.e2e8eshup5wn$.dlg@40tude.net> <51fadf40$0$6557$9b4e6d93@newsspool4.arcor-online.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: IenaDxMXK2hi7fvYcb+MlQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:16652 Date: 2013-08-02T10:11:32+02:00 List-Id: On Fri, 02 Aug 2013 00:20:47 +0200, Georg Bauhaus wrote: > On 01.08.13 21:24, Dmitry A. Kazakov wrote: > >> 7. Formal generic types of Ada are weakly typed. Matching is by structure. >> User-defined generic types (ADTs) are not supported. User-defined >> operations on formal types are not supported. The language of formal >> generic parameters is somewhere between FORTRAN-IV and K&R C. > > Not quite far from a misrepresentation of Ada generics. > Nothing in the languages mentioned can require type equivalence > by name in whatever generic formals, as in > > package N is > > type T is range -1 .. 1; > > generic > type S is new T; > package Pointless is end; > > type Q is range -1 .. 1; > > package Exmpl is new Pointless (Q); -- error > > end N; > > Equivalent structure of scalar types T and Q won't do. You cannot specify what belongs to a formal class it is decided by the structure of given type. Regarding your example the class you used is one created outside the generics. It is good that Ada 95 allowed this, but it does not change the nature of the language of formal generic specifications. >> 9. Generic units are basically non-testable. Substitutability issues are >> difficult to verify because of 7. > > With generics, substitutability issues arise as soon as one wishes to subsume > the mechanism of generic units under a formally extraneous type systems. > So, judicious use of this language features for things other than typing > might be the better choice. Here substitutability encompasses all parameters generics take, not just types. E.g. generic with function Foo (X : Integer) return Real; package Bar is ... You cannot verify if Baz function Baz (X : Integer) return Real; were substitutable in Bar for Foo. One of the motivations beyond types engaging in complex relationship was to limit the framework where substitution is considered. Parametric polymorphism of generics is way too loose, because it basically untyped. Worse is that it is any useful so long it remains untyped. Once you try to put types on it, it will be as "inconvenient" as any type system, while keeping all disadvantages of being strictly compile-time. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de