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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,91276ec2ea911d3f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Generic procedures and their parameters Date: Wed, 06 Sep 2006 14:36:24 +0200 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1157546184 13892 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Thunderbird 1.5.0.5 (X11/20060801) In-Reply-To: Xref: g2news2.google.com comp.lang.ada:6468 Date: 2006-09-06T14:36:24+02:00 List-Id: Dmitry A. Kazakov wrote: >> eneric >> type Index_Type is (<>); >> type Element_Type is private; >> type Array_Type is array (Index_Type range <>) of Element_Type; >> with function "<" (Left, Right : in Element_Type) return Boolean is <>; >> procedure Sort(To_Sort : in out Array_Type); >> >> My question is: what's the purpose of the third parameter (Array_Type)? >> Isn't it implied by the first two and therefore just redundant? > > Reverse. Actually Index_Type and Element_Type are redundant. In a better > Ada it should be: > > generic > type Container_Type is array (<>) of <>; > -- or "(<>) is limited private array" > with function "<" (Left, Right : in Container_Type'Element) > return Boolean is <>; > procedure Sort (To_Sort : in out Container_Type); OK, it makes perfect sense. > [ Even better it be non-generic: > > procedure Sort (To_Sort : in out Container_Of_Ordered'Class); > > where each container type (like an array) be a member of the class, if its > elements are in Ordered'Class. ] But then, you would need to have even such fundamental things like Integer belong to Ordered'Class. It's a shaky ground. > Regarding Array_Type being implied, it is not. You can have any number of > array types based on exactly same combination of index and element types. > These types will be different types: > > type I is ...; > type E is ...; > type Array1 is array (I range <>) of E; > type Array2 is array (I range <>) of E; > The types Array1 and Array2 are distinct types. And now I see. I'm still having troubles with the fact that "granularity" of type system in Ada can be much smaller than what can be achieved with structural differences only. > The reverse is a different story. It is a pity that Ada does not have > attributes to get the index and element types from the array type > (container type). Yes. > The next step would be getting "<" from the element type, > which would eliminate a need to have Sort generic. No, I disagree. There is a place for generic subprograms, otherwise we'd have everything in a single hierarchy with Object at the top. It's not a coincidence that "other languages" drift towards supporting generics, even if they already had such single-rooted hierarchies. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/