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!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Generic procedures and their parameters Date: 06 Sep 2006 09:02:51 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1157547771 767 192.74.137.71 (6 Sep 2006 13:02:51 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 6 Sep 2006 13:02:51 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news2.google.com comp.lang.ada:6471 Date: 2006-09-06T09:02:51-04:00 List-Id: "Dmitry A. Kazakov" writes: > On Wed, 06 Sep 2006 10:51:48 +0200, Maciej Sobczak 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); > > [ 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. ] I think you mean Sequence_Of_Ordered -- not all containers can be sorted. But I agree that it would be nice to have such a feature. It works for the built-in array types -- you magically get "and" if the component is Boolean, "<" if the component is discrete, ":=" if the component is non-limited. I don't know of a good way to do that sort of thing for user-defined containers. If generics could do that, then "array" could just be a generic, rather than having built-in syntax and semantics. Eiffel does it that way. - Bob