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!news3.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 08:56:35 -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 1157547395 767 192.74.137.71 (6 Sep 2006 12:56:35 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 6 Sep 2006 12:56:35 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news2.google.com comp.lang.ada:6470 Date: 2006-09-06T08:56:35-04:00 List-Id: Maciej Sobczak writes: > Hi, > > I have found the following signature for the sorting procedure: > > 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? Well, if you simply erase the Array_Type formal, then the reference to Array_Type in the declaration of To_Sort would be in error. And you cannot say this: generic type Index_Type is (<>); type Element_Type is private; with function "<" (Left, Right : in Element_Type) return Boolean is <>; procedure Sort(To_Sort : in out array (Index_Type range <>) of Element_Type); -- Illegal syntax! because Ada uses "by name" type equivalence (mostly). In this case, structural equivalence might be more convenient. You could do it this way: generic type Index_Type is (<>); type Element_Type is private; with function "<" (Left, Right : in Element_Type) return Boolean is <>; package Sorting is type Array_Type is array (Index_Type range <>) of Element_Type; procedure Sort(To_Sort : in out Array_Type); end Sorting; but that's less flexible for the client, because it can't use it's own array type. - Bob